-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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.