@@ -32,9 +32,10 @@ module.exports = async (pluginConfig, context) => {
3232 addReleases,
3333 } = resolveConfig ( pluginConfig , context ) ;
3434
35- const github = getClient ( { githubToken, githubUrl, githubApiPathPrefix, proxy} ) ;
35+ const octokit = getClient ( { githubToken, githubUrl, githubApiPathPrefix, proxy} ) ;
3636 // In case the repo changed name, get the new `repo`/`owner` as the search API will not follow redirects
37- const [ owner , repo ] = ( await github . repos . get ( parseGithubUrl ( repositoryUrl ) ) ) . data . full_name . split ( '/' ) ;
37+ const { data : repoData } = await octokit . request ( 'GET /repos/{owner}/{repo}' , parseGithubUrl ( repositoryUrl ) ) ;
38+ const [ owner , repo ] = repoData . full_name . split ( '/' ) ;
3839
3940 const errors = [ ] ;
4041
@@ -46,15 +47,27 @@ module.exports = async (pluginConfig, context) => {
4647 const shas = commits . map ( ( { hash} ) => hash ) ;
4748
4849 const searchQueries = getSearchQueries ( `repo:${ owner } /${ repo } +type:pr+is:merged` , shas ) . map (
49- async ( q ) => ( await github . search . issuesAndPullRequests ( { q} ) ) . data . items
50+ async ( q ) => ( await octokit . request ( 'GET /search/issues' , { q} ) ) . data . items
5051 ) ;
5152
52- const prs = await pFilter (
53- uniqBy ( flatten ( await Promise . all ( searchQueries ) ) , 'number' ) ,
54- async ( { number} ) =>
55- ( await github . pulls . listCommits ( { owner, repo, pull_number : number } ) ) . data . find ( ( { sha} ) => shas . includes ( sha ) ) ||
56- shas . includes ( ( await github . pulls . get ( { owner, repo, pull_number : number } ) ) . data . merge_commit_sha )
57- ) ;
53+ const searchQueriesResults = await Promise . all ( searchQueries ) ;
54+ const uniqueSearchQueriesResults = uniqBy ( flatten ( searchQueriesResults ) , 'number' ) ;
55+ const prs = await pFilter ( uniqueSearchQueriesResults , async ( { number} ) => {
56+ const commits = await octokit . paginate ( 'GET /repos/{owner}/{repo}/pulls/{pull_number}/commits' , {
57+ owner,
58+ repo,
59+ pull_number : number ,
60+ } ) ;
61+ const matchingCommit = commits . find ( ( { sha} ) => shas . includes ( sha ) ) ;
62+ if ( matchingCommit ) return matchingCommit ;
63+
64+ const { data : pullRequest } = await octokit . request ( 'GET /repos/{owner}/{repo}/pulls/{pull_number}' , {
65+ owner,
66+ repo,
67+ pull_number : number ,
68+ } ) ;
69+ return shas . includes ( pullRequest . merge_commit_sha ) ;
70+ } ) ;
5871
5972 debug (
6073 'found pull requests: %O' ,
@@ -87,17 +100,15 @@ module.exports = async (pluginConfig, context) => {
87100 debug ( 'create comment: %O' , comment ) ;
88101 const {
89102 data : { html_url : url } ,
90- } = await github . issues . createComment ( comment ) ;
103+ } = await octokit . request ( 'POST /repos/{owner}/{repo}/issues/{issue_number}/comments' , comment ) ;
91104 logger . log ( 'Added comment to issue #%d: %s' , issue . number , url ) ;
92105
93106 if ( releasedLabels ) {
94107 const labels = releasedLabels . map ( ( label ) => template ( label ) ( context ) ) ;
95- // Don’t use .issues.addLabels for GHE < 2.16 support
96- // https://github.com/semantic-release/github/issues/138
97- await github . request ( 'POST /repos/:owner/:repo/issues/:number/labels' , {
108+ await octokit . request ( 'POST /repos/{owner}/{repo}/issues/{issue_number}/labels' , {
98109 owner,
99110 repo,
100- number : issue . number ,
111+ issue_number : issue . number ,
101112 data : labels ,
102113 } ) ;
103114 logger . log ( 'Added labels %O to issue #%d' , labels , issue . number ) ;
@@ -120,7 +131,7 @@ module.exports = async (pluginConfig, context) => {
120131 if ( failComment === false || failTitle === false ) {
121132 logger . log ( 'Skip closing issue.' ) ;
122133 } else {
123- const srIssues = await findSRIssues ( github , failTitle , owner , repo ) ;
134+ const srIssues = await findSRIssues ( octokit , failTitle , owner , repo ) ;
124135
125136 debug ( 'found semantic-release issues: %O' , srIssues ) ;
126137
@@ -132,7 +143,7 @@ module.exports = async (pluginConfig, context) => {
132143 debug ( 'closing issue: %O' , updateIssue ) ;
133144 const {
134145 data : { html_url : url } ,
135- } = await github . issues . update ( updateIssue ) ;
146+ } = await octokit . request ( 'PATCH /repos/{owner}/{repo}/issues/{issue_number}' , updateIssue ) ;
136147 logger . log ( 'Closed issue #%d: %s.' , issue . number , url ) ;
137148 } catch ( error ) {
138149 errors . push ( error ) ;
@@ -153,7 +164,12 @@ module.exports = async (pluginConfig, context) => {
153164 addReleases === 'top'
154165 ? additionalReleases . concat ( '\n---\n' , nextRelease . notes )
155166 : nextRelease . notes . concat ( '\n---\n' , additionalReleases ) ;
156- await github . repos . updateRelease ( { owner, repo, release_id : ghRelaseId , body : newBody } ) ;
167+ await octokit . request ( 'PATCH /repos/{owner}/{repo}/releases/{release_id}' , {
168+ owner,
169+ repo,
170+ release_id : ghRelaseId ,
171+ body : newBody ,
172+ } ) ;
157173 }
158174 }
159175 }
0 commit comments