@itcase/config 1.7.9 → 1.7.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -17,8 +17,11 @@ const releaseNotesFromIssuesScript = join(
|
|
|
17
17
|
'releaseNotesFromIssues.js',
|
|
18
18
|
)
|
|
19
19
|
|
|
20
|
-
// Ссылки на задачи из PR.
|
|
21
|
-
//
|
|
20
|
+
// Ссылки на задачи из PR.
|
|
21
|
+
// RELEASE_NOTES_PULLS_REPO — репозиторий pull request'ов, если это не репозиторий Actions.
|
|
22
|
+
// Его и задачи читает RELEASE_NOTES_GH_TOKEN.
|
|
23
|
+
// Без RELEASE_NOTES_PULLS_REPO pull request'ы читает GITHUB_TOKEN в текущем репозитории.
|
|
24
|
+
// RELEASE_NOTES_ISSUES_REPO — репозиторий задач.
|
|
22
25
|
const releaseNotesFromIssuesPlugin = [
|
|
23
26
|
'@semantic-release/exec',
|
|
24
27
|
{
|
|
@@ -14,12 +14,22 @@ import { join } from 'node:path'
|
|
|
14
14
|
*/
|
|
15
15
|
const [lastTagArg, nextTagArg] = process.argv.slice(2)
|
|
16
16
|
|
|
17
|
-
//
|
|
18
|
-
|
|
17
|
+
// Pull requests of the repository where Actions runs.
|
|
18
|
+
// Used only when RELEASE_NOTES_PULLS_REPO is not set.
|
|
19
|
+
const repositoryToken = process.env.GITHUB_TOKEN || process.env.GH_TOKEN
|
|
20
|
+
|
|
21
|
+
// Issues and, when configured, pull requests of another repository.
|
|
22
|
+
// The workflow token cannot read them.
|
|
23
|
+
const issuesToken = process.env.RELEASE_NOTES_GH_TOKEN
|
|
19
24
|
|
|
20
25
|
const currentProjectOwner = process.env.GITHUB_REPOSITORY?.split('/')[0]
|
|
21
26
|
const currentProjectRepo = process.env.GITHUB_REPOSITORY?.split('/')[1]
|
|
22
27
|
|
|
28
|
+
// Repository with pull requests, when it is not the Actions repository.
|
|
29
|
+
const releaseNotesPullsRepo = process.env.RELEASE_NOTES_PULLS_REPO
|
|
30
|
+
const pullsProjectOwner = releaseNotesPullsRepo?.split('/')[0]
|
|
31
|
+
const pullsProjectRepo = releaseNotesPullsRepo?.split('/')[1]
|
|
32
|
+
|
|
23
33
|
// Repository with all issues. Not this project repository.
|
|
24
34
|
// Used when PR text contains "Issue: #123".
|
|
25
35
|
const releaseNotesIssuesRepo = process.env.RELEASE_NOTES_ISSUES_REPO
|
|
@@ -27,8 +37,28 @@ const releaseNotesIssuesRepo = process.env.RELEASE_NOTES_ISSUES_REPO
|
|
|
27
37
|
const issuesProjectOwner = releaseNotesIssuesRepo?.split('/')[0]
|
|
28
38
|
const issuesProjectRepo = releaseNotesIssuesRepo?.split('/')[1]
|
|
29
39
|
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
const pullRequestOwner = pullsProjectOwner || currentProjectOwner
|
|
41
|
+
const pullRequestRepo = pullsProjectRepo || currentProjectRepo
|
|
42
|
+
const pullRequestToken = releaseNotesPullsRepo ? issuesToken : repositoryToken
|
|
43
|
+
|
|
44
|
+
if (!currentProjectOwner || !currentProjectRepo) {
|
|
45
|
+
throw new Error('Missing "GITHUB_REPOSITORY"')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (releaseNotesPullsRepo && (!pullsProjectOwner || !pullsProjectRepo)) {
|
|
49
|
+
throw new Error('Invalid "RELEASE_NOTES_PULLS_REPO". Expected "owner/repo"')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!pullRequestToken) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
releaseNotesPullsRepo
|
|
55
|
+
? 'Missing "RELEASE_NOTES_GH_TOKEN"'
|
|
56
|
+
: 'Missing "GITHUB_TOKEN"',
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!issuesToken) {
|
|
61
|
+
throw new Error('Missing "RELEASE_NOTES_GH_TOKEN"')
|
|
32
62
|
}
|
|
33
63
|
|
|
34
64
|
if (!issuesProjectOwner || !issuesProjectRepo) {
|
|
@@ -269,7 +299,7 @@ async function run() {
|
|
|
269
299
|
}
|
|
270
300
|
|
|
271
301
|
// Small helper for GitHub REST API with common headers and query serialization.
|
|
272
|
-
async function fetchGithubApi(pathname, queryParams = {}) {
|
|
302
|
+
async function fetchGithubApi(pathname, token, queryParams = {}) {
|
|
273
303
|
const apiUrl = new URL(`https://api.github.com${pathname}`)
|
|
274
304
|
|
|
275
305
|
for (const [key, value] of Object.entries(queryParams)) {
|
|
@@ -282,7 +312,7 @@ async function fetchGithubApi(pathname, queryParams = {}) {
|
|
|
282
312
|
const response = await fetch(apiUrl, {
|
|
283
313
|
headers: {
|
|
284
314
|
Accept: 'application/vnd.github+json',
|
|
285
|
-
Authorization: `Bearer ${
|
|
315
|
+
Authorization: `Bearer ${token}`,
|
|
286
316
|
'User-Agent': 'semantic-release-issues-notes',
|
|
287
317
|
// GitHub REST API version header
|
|
288
318
|
'X-GitHub-Api-Version': '2026-03-10',
|
|
@@ -426,10 +456,24 @@ function getGitCommitsInRange(fromRef, toRef) {
|
|
|
426
456
|
async function getAssociatedPullRequestsForCommit(commitSha) {
|
|
427
457
|
// GitHub endpoint that returns PRs linked to a commit SHA.
|
|
428
458
|
// Works for both merge-commit and regular commits associated with PRs.
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
459
|
+
// The commit has to exist in pullRequestOwner/pullRequestRepo.
|
|
460
|
+
// A SHA from another git history is not a pull request there.
|
|
461
|
+
try {
|
|
462
|
+
const response = await fetchGithubApi(
|
|
463
|
+
`/repos/${pullRequestOwner}/${pullRequestRepo}/commits/${commitSha}/pulls`,
|
|
464
|
+
pullRequestToken,
|
|
465
|
+
)
|
|
466
|
+
return Array.isArray(response) ? response : []
|
|
467
|
+
} catch (error) {
|
|
468
|
+
if (String(error?.message).includes('(422)')) {
|
|
469
|
+
console.error(
|
|
470
|
+
`[release-notes] Commit ${commitSha} is not in ${pullRequestOwner}/${pullRequestRepo}`,
|
|
471
|
+
)
|
|
472
|
+
return []
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
throw error
|
|
476
|
+
}
|
|
433
477
|
}
|
|
434
478
|
|
|
435
479
|
async function loadIssuesInBatches(refs) {
|
|
@@ -449,7 +493,7 @@ async function loadIssue(ref) {
|
|
|
449
493
|
const [issueOwner, issueRepo] = repoRef.split('/')
|
|
450
494
|
const issuePath = `/repos/${issueOwner}/${issueRepo}/issues/${issueNumber}`
|
|
451
495
|
try {
|
|
452
|
-
return await fetchGithubApi(issuePath)
|
|
496
|
+
return await fetchGithubApi(issuePath, issuesToken)
|
|
453
497
|
} catch (error) {
|
|
454
498
|
throw new Error(
|
|
455
499
|
`Failed to load issue for ref="${ref}" using path="${issuePath}"`,
|