@itcase/config 1.7.10 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itcase/config",
3
- "version": "1.7.10",
3
+ "version": "1.7.11",
4
4
  "author": "ITCase",
5
5
  "description": "ITCase Config",
6
6
  "engines": {
@@ -18,8 +18,9 @@ const releaseNotesFromIssuesScript = join(
18
18
  )
19
19
 
20
20
  // Ссылки на задачи из PR.
21
- // Pull request'ы текущего репозитория читает GITHUB_TOKEN.
22
- // Задачи другого репозитория читает RELEASE_NOTES_GH_TOKEN.
21
+ // RELEASE_NOTES_PULLS_REPO — репозиторий pull request'ов, если это не репозиторий Actions.
22
+ // Его и задачи читает RELEASE_NOTES_GH_TOKEN.
23
+ // Без RELEASE_NOTES_PULLS_REPO pull request'ы читает GITHUB_TOKEN в текущем репозитории.
23
24
  // RELEASE_NOTES_ISSUES_REPO — репозиторий задач.
24
25
  const releaseNotesFromIssuesPlugin = [
25
26
  '@semantic-release/exec',
@@ -14,15 +14,22 @@ import { join } from 'node:path'
14
14
  */
15
15
  const [lastTagArg, nextTagArg] = process.argv.slice(2)
16
16
 
17
- // Pull requests of this repository. In GitHub Actions this is the workflow token.
17
+ // Pull requests of the repository where Actions runs.
18
+ // Used only when RELEASE_NOTES_PULLS_REPO is not set.
18
19
  const repositoryToken = process.env.GITHUB_TOKEN || process.env.GH_TOKEN
19
20
 
20
- // Issues live in another repository. The workflow token cannot read them.
21
+ // Issues and, when configured, pull requests of another repository.
22
+ // The workflow token cannot read them.
21
23
  const issuesToken = process.env.RELEASE_NOTES_GH_TOKEN
22
24
 
23
25
  const currentProjectOwner = process.env.GITHUB_REPOSITORY?.split('/')[0]
24
26
  const currentProjectRepo = process.env.GITHUB_REPOSITORY?.split('/')[1]
25
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
+
26
33
  // Repository with all issues. Not this project repository.
27
34
  // Used when PR text contains "Issue: #123".
28
35
  const releaseNotesIssuesRepo = process.env.RELEASE_NOTES_ISSUES_REPO
@@ -30,8 +37,24 @@ const releaseNotesIssuesRepo = process.env.RELEASE_NOTES_ISSUES_REPO
30
37
  const issuesProjectOwner = releaseNotesIssuesRepo?.split('/')[0]
31
38
  const issuesProjectRepo = releaseNotesIssuesRepo?.split('/')[1]
32
39
 
33
- if (!currentProjectOwner || !currentProjectRepo || !repositoryToken) {
34
- throw new Error('Missing "GITHUB_REPOSITORY" or "GITHUB_TOKEN"')
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
+ )
35
58
  }
36
59
 
37
60
  if (!issuesToken) {
@@ -433,11 +456,24 @@ function getGitCommitsInRange(fromRef, toRef) {
433
456
  async function getAssociatedPullRequestsForCommit(commitSha) {
434
457
  // GitHub endpoint that returns PRs linked to a commit SHA.
435
458
  // Works for both merge-commit and regular commits associated with PRs.
436
- const response = await fetchGithubApi(
437
- `/repos/${currentProjectOwner}/${currentProjectRepo}/commits/${commitSha}/pulls`,
438
- repositoryToken,
439
- )
440
- return Array.isArray(response) ? response : []
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
+ }
441
477
  }
442
478
 
443
479
  async function loadIssuesInBatches(refs) {