Merge pull request #1305 from mikepenz/develop

dev -> main
This commit is contained in:
Mike Penz
2024-03-01 14:21:25 +01:00
committed by GitHub
7 changed files with 432 additions and 282 deletions
+66 -1
View File
@@ -1,4 +1,5 @@
import {filterTags, prepareAndSortTags, TagInfo} from '../src/pr-collector/tags'
import { validateTransformer } from '../src/pr-collector/regexUtils'
import {filterTags, prepareAndSortTags, TagInfo, transformTags} from '../src/pr-collector/tags'
jest.setTimeout(180000)
@@ -114,3 +115,67 @@ it('Should filter tags correctly using the regex', async () => {
expect(filtered).toStrictEqual(`api-0.0.1,api-0.0.1-rc01,api-10.1.0-2`)
})
it('Should filter tags correctly using the regex (inverse)', async () => {
const tags: TagInfo[] = [
{name: 'api-0.0.1', commit: ''},
{name: 'api-0.0.1-rc01', commit: ''},
{name: 'config-0.1.0', commit: ''},
{name: '0.1.0-b01', commit: ''},
{name: '1.0.0', commit: ''},
{name: '1.0.0-a01', commit: ''},
{name: '2.0.0', commit: ''},
{name: 'ap-10.0.0', commit: ''},
{name: '10.1.0', commit: ''},
{name: 'api-10.1.0-2', commit: ''},
{name: '20.0.2', commit: ''}
]
const tagResolver = {
method: 'non-existing-method',
filter: {
pattern: '^(?!\\w+-)(.+)',
flags: 'gu'
}
}
const filtered = filterTags(tags, tagResolver)
.map(function (tag) {
return tag.name
})
.join(',')
expect(filtered).toStrictEqual(`0.1.0-b01,1.0.0,1.0.0-a01,2.0.0,10.1.0,20.0.2`)
})
it('Should transform tags correctly using the regex', async () => {
const tags: TagInfo[] = [
{name: 'api-0.0.1', commit: ''},
{name: 'api-0.0.1-rc01', commit: ''},
{name: 'config-0.1.0', commit: ''},
{name: '0.1.0-b01', commit: ''},
{name: '2.0.0', commit: ''},
{name: '10.1.0', commit: ''},
{name: 'api-10.1.0-2', commit: ''},
{name: '20.0.2', commit: ''}
]
const tagResolver = {
method: 'non-existing-method',
transformer: {
pattern: '(api\-)?(.+)',
target: "$2"
}
}
const transformer = validateTransformer(tagResolver.transformer)
if(transformer != null) {
const transformed = transformTags(tags, transformer)
.map(function (tag) {
return tag.name
})
.join(',')
expect(transformed).toStrictEqual(`0.0.1,0.0.1-rc01,config-0.1.0,0.1.0-b01,2.0.0,10.1.0,10.1.0-2,20.0.2`)
}
})
Generated Vendored
+41 -16
View File
@@ -1020,7 +1020,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.prepareAndSortTags = exports.filterTags = exports.Tags = void 0;
exports.prepareAndSortTags = exports.transformTags = exports.filterTags = exports.Tags = void 0;
const core = __importStar(__nccwpck_require__(2186));
const github = __importStar(__nccwpck_require__(5438));
const semver = __importStar(__nccwpck_require__(1383));
@@ -1219,6 +1219,7 @@ function transformTags(tags, transformer) {
}
});
}
exports.transformTags = transformTags;
/*
Sorts an array of tags as shown below:
@@ -2145,7 +2146,7 @@ class GithubRepository extends BaseRepository_1.BaseRepository {
owner,
repo,
state: 'closed',
sort: 'merged',
sort: 'updated',
per_page: `${Math.min(100, maxPullRequests)}`,
direction: 'desc'
});
@@ -2379,11 +2380,13 @@ class GithubRepository extends BaseRepository_1.BaseRepository {
}
fetchedEnough(pullRequests, fromDate) {
for (let i = 0; i < Math.min(pullRequests.length, 3); i++) {
// we get PRs paged by updated timestamp, there is a chance that PRs come out of merged order as a result of this
// ensure we get enough PRs to cover the expected spectrum.
const firstPR = pullRequests[i];
if (!firstPR.merged_at) {
// no merged_at timestamp -> look for the next
if (!firstPR.updated_at) {
// no updated_at timestamp -> look for the next
}
else if (fromDate.isAfter((0, moment_1.default)(firstPR.merged_at))) {
else if (fromDate.isAfter((0, moment_1.default)(firstPR.updated_at))) {
return true;
}
else {
@@ -6661,7 +6664,7 @@ var import_graphql = __nccwpck_require__(8467);
var import_auth_token = __nccwpck_require__(334);
// pkg/dist-src/version.js
var VERSION = "5.0.2";
var VERSION = "5.1.0";
// pkg/dist-src/index.js
var noop = () => {
@@ -10037,7 +10040,7 @@ var import_endpoint = __nccwpck_require__(9440);
var import_universal_user_agent = __nccwpck_require__(5030);
// pkg/dist-src/version.js
var VERSION = "8.1.6";
var VERSION = "8.2.0";
// pkg/dist-src/is-plain-object.js
function isPlainObject(value) {
@@ -10181,11 +10184,17 @@ async function getResponseData(response) {
function toErrorMessage(data) {
if (typeof data === "string")
return data;
let suffix;
if ("documentation_url" in data) {
suffix = ` - ${data.documentation_url}`;
} else {
suffix = "";
}
if ("message" in data) {
if (Array.isArray(data.errors)) {
return `${data.message}: ${data.errors.map(JSON.stringify).join(", ")}`;
return `${data.message}: ${data.errors.map(JSON.stringify).join(", ")}${suffix}`;
}
return data.message;
return `${data.message}${suffix}`;
}
return `Unknown error: ${JSON.stringify(data)}`;
}
@@ -24449,35 +24458,43 @@ const coerce = (version, options) => {
let match = null
if (!options.rtl) {
match = version.match(re[t.COERCE])
match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE])
} else {
// Find the right-most coercible string that does not share
// a terminus with a more left-ward coercible string.
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
// With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
//
// Walk through the string checking with a /g regexp
// Manually set the index so as to pick up overlapping matches.
// Stop when we get a match that ends at the string end, since no
// coercible string can be more right-ward without the same terminus.
const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL]
let next
while ((next = re[t.COERCERTL].exec(version)) &&
while ((next = coerceRtlRegex.exec(version)) &&
(!match || match.index + match[0].length !== version.length)
) {
if (!match ||
next.index + next[0].length !== match.index + match[0].length) {
match = next
}
re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length
coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length
}
// leave it in a clean state
re[t.COERCERTL].lastIndex = -1
coerceRtlRegex.lastIndex = -1
}
if (match === null) {
return null
}
return parse(`${match[2]}.${match[3] || '0'}.${match[4] || '0'}`, options)
const major = match[2]
const minor = match[3] || '0'
const patch = match[4] || '0'
const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : ''
const build = options.includePrerelease && match[6] ? `+${match[6]}` : ''
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options)
}
module.exports = coerce
@@ -25169,12 +25186,17 @@ createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`)
// Coercion.
// Extract anything that could conceivably be a part of a valid semver
createToken('COERCE', `${'(^|[^\\d])' +
createToken('COERCEPLAIN', `${'(^|[^\\d])' +
'(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`)
createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`)
createToken('COERCEFULL', src[t.COERCEPLAIN] +
`(?:${src[t.PRERELEASE]})?` +
`(?:${src[t.BUILD]})?` +
`(?:$|[^\\d])`)
createToken('COERCERTL', src[t.COERCE], true)
createToken('COERCERTLFULL', src[t.COERCEFULL], true)
// Tilde ranges.
// Meaning is "reasonably at or greater than"
@@ -38819,6 +38841,9 @@ function httpRedirectFetch (fetchParams, response) {
// https://fetch.spec.whatwg.org/#cors-non-wildcard-request-header-name
request.headersList.delete('authorization')
// https://fetch.spec.whatwg.org/#authentication-entries
request.headersList.delete('proxy-authorization', true)
// "Cookie" and "Host" are forbidden request-headers, which undici doesn't implement.
request.headersList.delete('cookie')
request.headersList.delete('host')
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+309 -251
View File
File diff suppressed because it is too large Load Diff
+8 -8
View File
@@ -42,24 +42,24 @@
"gitea-js": "^1.20.1",
"https-proxy-agent": "^7.0.2",
"moment": "^2.30.1",
"semver": "^7.5.4"
"semver": "^7.6.0"
},
"devDependencies": {
"@types/jest": "^29.5.11",
"@types/node": "^20.11.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.17",
"@types/semver": "^7.5.6",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.56.0",
"eslint-plugin-github": "^4.10.1",
"eslint-plugin-jest": "^27.6.2",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"jest-circus": "^29.7.0",
"js-yaml": "^4.1.0",
"prettier": "3.1.1",
"ts-jest": "^29.1.1",
"prettier": "3.2.5",
"ts-jest": "^29.1.2",
"typescript": "^5.3.3"
}
}
+1 -1
View File
@@ -211,7 +211,7 @@ export function filterTags(tags: TagInfo[], tagResolver: TagResolver): TagInfo[]
/**
* Helper function to transform the tag name given the transformer
*/
function transformTags(tags: TagInfo[], transformer: RegexTransformer): TagInfo[] {
export function transformTags(tags: TagInfo[], transformer: RegexTransformer): TagInfo[] {
return tags.map(function (tag) {
if (transformer.pattern) {
const transformedName = tag.name.replace(transformer.pattern, transformer.target)
+6 -4
View File
@@ -100,7 +100,7 @@ export class GithubRepository extends BaseRepository {
owner,
repo,
state: 'closed',
sort: 'merged',
sort: 'updated',
per_page: `${Math.min(100, maxPullRequests)}`,
direction: 'desc'
})
@@ -291,10 +291,12 @@ export class GithubRepository extends BaseRepository {
private fetchedEnough(pullRequests: PullsListData, fromDate: moment.Moment): boolean {
for (let i = 0; i < Math.min(pullRequests.length, 3); i++) {
// we get PRs paged by updated timestamp, there is a chance that PRs come out of merged order as a result of this
// ensure we get enough PRs to cover the expected spectrum.
const firstPR = pullRequests[i]
if (!firstPR.merged_at) {
// no merged_at timestamp -> look for the next
} else if (fromDate.isAfter(moment(firstPR.merged_at))) {
if (!firstPR.updated_at) {
// no updated_at timestamp -> look for the next
} else if (fromDate.isAfter(moment(firstPR.updated_at))) {
return true
} else {
break // not enough PRs yet, go further