@@ -32,9 +32,10 @@ module.exports = async (pluginConfig, context) => {
32
32
addReleases,
33
33
} = resolveConfig ( pluginConfig , context ) ;
34
34
35
- const github = getClient ( { githubToken, githubUrl, githubApiPathPrefix, proxy} ) ;
35
+ const octokit = getClient ( { githubToken, githubUrl, githubApiPathPrefix, proxy} ) ;
36
36
// 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 ( '/' ) ;
38
39
39
40
const errors = [ ] ;
40
41
@@ -46,15 +47,27 @@ module.exports = async (pluginConfig, context) => {
46
47
const shas = commits . map ( ( { hash} ) => hash ) ;
47
48
48
49
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
50
51
) ;
51
52
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
+ } ) ;
58
71
59
72
debug (
60
73
'found pull requests: %O' ,
@@ -87,17 +100,15 @@ module.exports = async (pluginConfig, context) => {
87
100
debug ( 'create comment: %O' , comment ) ;
88
101
const {
89
102
data : { html_url : url } ,
90
- } = await github . issues . createComment ( comment ) ;
103
+ } = await octokit . request ( 'POST /repos/{owner}/{repo}/issues/{issue_number}/comments' , comment ) ;
91
104
logger . log ( 'Added comment to issue #%d: %s' , issue . number , url ) ;
92
105
93
106
if ( releasedLabels ) {
94
107
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' , {
98
109
owner,
99
110
repo,
100
- number : issue . number ,
111
+ issue_number : issue . number ,
101
112
data : labels ,
102
113
} ) ;
103
114
logger . log ( 'Added labels %O to issue #%d' , labels , issue . number ) ;
@@ -120,7 +131,7 @@ module.exports = async (pluginConfig, context) => {
120
131
if ( failComment === false || failTitle === false ) {
121
132
logger . log ( 'Skip closing issue.' ) ;
122
133
} else {
123
- const srIssues = await findSRIssues ( github , failTitle , owner , repo ) ;
134
+ const srIssues = await findSRIssues ( octokit , failTitle , owner , repo ) ;
124
135
125
136
debug ( 'found semantic-release issues: %O' , srIssues ) ;
126
137
@@ -132,7 +143,7 @@ module.exports = async (pluginConfig, context) => {
132
143
debug ( 'closing issue: %O' , updateIssue ) ;
133
144
const {
134
145
data : { html_url : url } ,
135
- } = await github . issues . update ( updateIssue ) ;
146
+ } = await octokit . request ( 'PATCH /repos/{owner}/{repo}/issues/{issue_number}' , updateIssue ) ;
136
147
logger . log ( 'Closed issue #%d: %s.' , issue . number , url ) ;
137
148
} catch ( error ) {
138
149
errors . push ( error ) ;
@@ -153,7 +164,12 @@ module.exports = async (pluginConfig, context) => {
153
164
addReleases === 'top'
154
165
? additionalReleases . concat ( '\n---\n' , nextRelease . notes )
155
166
: 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
+ } ) ;
157
173
}
158
174
}
159
175
}
0 commit comments