Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github.comments feature to add comments to merged pull requests a…
…nd closed issues
- Loading branch information
Showing
5 changed files
with
109 additions
and
7 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
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Totally much borrowed from https://github.com/semantic-release/github/blob/master/lib/success.js | ||
import issueParser from 'issue-parser'; | ||
|
||
const getSearchQueries = (base, commits, separator = '+') => { | ||
return commits.reduce((searches, commit) => { | ||
const lastSearch = searches[searches.length - 1]; | ||
if (lastSearch && lastSearch.length + commit.length <= 256 - separator.length) { | ||
searches[searches.length - 1] = `${lastSearch}${separator}${commit}`; | ||
} else { | ||
searches.push(`${base}${separator}${commit}`); | ||
} | ||
|
||
return searches; | ||
}, []); | ||
}; | ||
|
||
export const searchQueries = (client, owner, repo, shas) => | ||
getSearchQueries(`repo:${owner}/${repo}+type:pr+is:merged`, shas).map( | ||
async q => (await client.search.issuesAndPullRequests({ q })).data.items | ||
); | ||
|
||
export const getCommitsFromChangelog = changelog => { | ||
const regex = /\(([a-f0-9]{7,})\)/i; | ||
return changelog.split('\n').flatMap(message => { | ||
const match = message.match(regex); | ||
if (match) return match[1]; | ||
return []; | ||
}); | ||
}; | ||
|
||
export const getResolvedIssuesFromChangelog = (host, owner, repo, changelog) => { | ||
const parser = issueParser('github', { hosts: [host] }); | ||
return changelog | ||
.split('\n') | ||
.map(parser) | ||
.flatMap(parsed => parsed.actions.close) | ||
.filter(action => !action.slug || action.slug === `${owner}/${repo}`) | ||
.map(action => ({ type: 'issue', number: parseInt(action.issue, 10) })); | ||
}; |
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