-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…907) * feat: add graphql query loader `loadGetSRIssuesQuery` to fetch SRIssues * chore: add new `RELEASE_FAIL_LABEL` constant * feat: integrate issues fetch with graphql * feat: add fallback to searchAPI for backward compatibility * feat: integrated config label in SRIssues search * fix: error `getSRIssue` graphql query label param type * fix: undefined `data` property destructed from graphql reponse * refactor: modified wrong `body` property in query * refactor: remove conditions from searchAPI fallback logic * refactor: replace `getSRIssues` graphql query `label` param with `filter` * feat: implement unique issue sorting to address fallback `backwardIssues` conflict * feat: modify `findSRIssue` integration in `success` script; add `logger` to its params; * feat: integrate opinionated `RELEASE_FAIL_LABEL` into `fail` script * chore: Questions and lint fixes * refactor: modified `findSRIssues` integration in `fail` script * test: fixed `findSRIssue` units test * test: fixed `fail` unit tests * test: fix integrations test * test: fixed `success` unit tests * test: `Verify, release and notify success` fix attempt * test: addressed `"Verify, release and notify success"` case in `integrations` * test: fix `success` units * test: fix `fail` units * refactor: remove error object from searchAPI fallback error handle * test: add new case `"Handle error in searchAPI fallback"` * Revert "refactor: remove conditions from searchAPI fallback logic" This reverts commit a478a2b. * modified `RELEASE_FAIL_LABEL` value to `semantic-release` * test: fix cases for conditional `searchAPI` fallback consumption * Update lib/resolve-config.js
- Loading branch information
Showing
8 changed files
with
998 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export const ISSUE_ID = "<!-- semantic-release:github -->"; | ||
|
||
export const RELEASE_NAME = "GitHub release"; | ||
|
||
export const RELEASE_FAIL_LABEL = "semantic-release"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,63 @@ | ||
import { ISSUE_ID } from "./definitions/constants.js"; | ||
import { uniqBy } from "lodash-es"; | ||
import { ISSUE_ID, RELEASE_FAIL_LABEL } from "./definitions/constants.js"; | ||
|
||
export default async (octokit, logger, title, labels, owner, repo) => { | ||
let issues = []; | ||
|
||
export default async (octokit, title, owner, repo) => { | ||
const { | ||
data: { items: issues }, | ||
} = await octokit.request("GET /search/issues", { | ||
q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`, | ||
repository: { | ||
issues: { nodes: issueNodes }, | ||
}, | ||
} = await octokit.graphql(loadGetSRIssuesQuery, { | ||
owner, | ||
repo, | ||
filter: { | ||
labels: (labels || []).concat([RELEASE_FAIL_LABEL]), | ||
}, | ||
}); | ||
|
||
return issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID)); | ||
issues.push(...issueNodes); | ||
|
||
/** | ||
* BACKWARD COMPATIBILITY: Fallback to the search API if the issue was not found in the GraphQL response. | ||
* This fallback will be removed in a future release | ||
*/ | ||
if (issueNodes.length === 0) { | ||
try { | ||
const { | ||
data: { items: backwardIssues }, | ||
} = await octokit.request("GET /search/issues", { | ||
q: `in:title+repo:${owner}/${repo}+type:issue+state:open+${title}`, | ||
}); | ||
issues.push(...backwardIssues); | ||
} catch (error) { | ||
logger.log( | ||
"An error occured fetching issue via fallback (with GH SearchAPI)", | ||
); | ||
} | ||
} | ||
|
||
const uniqueSRIssues = uniqBy( | ||
issues.filter((issue) => issue.body && issue.body.includes(ISSUE_ID)), | ||
"number", | ||
); | ||
|
||
return uniqueSRIssues; | ||
}; | ||
|
||
/** | ||
* GraphQL Query to et the semantic-release issues for a repository. | ||
*/ | ||
const loadGetSRIssuesQuery = `#graphql | ||
query getSRIssues($owner: String!, $repo: String!, $filter: IssueFilters) { | ||
repository(owner: $owner, name: $repo) { | ||
issues(first: 100, states: OPEN, filterBy: $filter) { | ||
nodes { | ||
number | ||
title | ||
body | ||
} | ||
} | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.