@@ -5889,6 +5889,115 @@ function wrappy (fn, cb) {
5889
5889
}
5890
5890
5891
5891
5892
+ /***/ } ) ,
5893
+
5894
+ /***/ 465 :
5895
+ /***/ ( ( module , __unused_webpack_exports , __nccwpck_require__ ) => {
5896
+
5897
+ "use strict" ;
5898
+
5899
+ const github = __nccwpck_require__ ( 438 ) ;
5900
+ const { logInfo } = __nccwpck_require__ ( 653 ) ;
5901
+
5902
+ const ISSUE_LABEL = 'notify-release' ;
5903
+ const ISSUE_TITLE = 'Release pending!' ;
5904
+ const STATE_OPEN = 'open' ;
5905
+ const STATE_CLOSED = 'closed' ;
5906
+
5907
+ async function createIssue ( token , issueBody ) {
5908
+ const octokit = github . getOctokit ( token ) ;
5909
+
5910
+ return octokit . issues . create ( {
5911
+ ...github . context . repo ,
5912
+ title : ISSUE_TITLE ,
5913
+ body : issueBody ,
5914
+ labels : [ ISSUE_LABEL ] ,
5915
+ } ) ;
5916
+ }
5917
+
5918
+ async function getLastOpenPendingIssue ( token ) {
5919
+ const octokit = github . getOctokit ( token ) ;
5920
+ const { owner, repo } = github . context . repo ;
5921
+
5922
+ const pendingIssues = await octokit . request ( `GET /repos/{owner}/{repo}/issues` , {
5923
+ owner,
5924
+ repo,
5925
+ creator : 'app/github-actions' ,
5926
+ state : STATE_OPEN ,
5927
+ sort : 'created' ,
5928
+ direction : 'desc' ,
5929
+ labels : ISSUE_LABEL
5930
+ } ) ;
5931
+
5932
+ return pendingIssues . data . length ? pendingIssues . data [ 0 ] : null ;
5933
+ }
5934
+
5935
+ async function updateLastOpenPendingIssue ( token , issueBody , issueNo ) {
5936
+ const octokit = github . getOctokit ( token ) ;
5937
+ const { owner, repo } = github . context . repo ;
5938
+
5939
+ const updatedIssue = await octokit . request ( `PATCH /repos/{owner}/{repo}/issues/${ issueNo } ` , {
5940
+ owner,
5941
+ repo,
5942
+ title : ISSUE_TITLE ,
5943
+ body : issueBody
5944
+ } ) ;
5945
+
5946
+ return updatedIssue . data . length ? updatedIssue . data [ 0 ] : null ;
5947
+ }
5948
+
5949
+ async function createOrUpdateIssue ( token , unreleasedCommits , pendingIssue , latestRelease , commitMessageLines ) {
5950
+ const commitStr = unreleasedCommits . map ( ( commit ) => `Commit: ${ formatCommitMessage ( commit . commit . message , commitMessageLines ) }
5951
+ Author: ${ commit . commit . author . name }
5952
+
5953
+ ` ) . join ( '' ) ;
5954
+ const issueBody = `Unreleased commits have been found which are pending release, please publish the changes.
5955
+
5956
+ ### Commits since the last release
5957
+ ${ commitStr } ` ;
5958
+
5959
+ if ( pendingIssue ) {
5960
+ await updateLastOpenPendingIssue ( token , issueBody , pendingIssue . number ) ;
5961
+ logInfo ( `Issue ${ pendingIssue . number } has been updated` ) ;
5962
+ } else {
5963
+ const issueNo = await createIssue ( token , issueBody ) ;
5964
+ logInfo ( `New issue has been created. Issue No. - ${ issueNo } ` ) ;
5965
+ }
5966
+ }
5967
+
5968
+ function formatCommitMessage ( fullCommitMessage , numberOfLines ) {
5969
+ if ( ! numberOfLines || numberOfLines < 0 ) {
5970
+ return fullCommitMessage ;
5971
+ }
5972
+ return fullCommitMessage
5973
+ . split ( '\n' )
5974
+ . slice ( 0 , numberOfLines )
5975
+ . join ( '\n' )
5976
+ . trim ( ) ;
5977
+ }
5978
+
5979
+ async function closeIssue ( token , issueNo ) {
5980
+ const octokit = github . getOctokit ( token ) ;
5981
+ const { owner, repo } = github . context . repo ;
5982
+
5983
+ await octokit . request ( `PATCH /repos/{owner}/{repo}/issues/${ issueNo } ` , {
5984
+ owner,
5985
+ repo,
5986
+ state : STATE_CLOSED
5987
+ } ) ;
5988
+ logInfo ( `Closed issue no. - ${ issueNo } ` ) ;
5989
+ }
5990
+
5991
+ module . exports = {
5992
+ createIssue,
5993
+ getLastOpenPendingIssue,
5994
+ updateLastOpenPendingIssue,
5995
+ formatCommitMessage,
5996
+ createOrUpdateIssue,
5997
+ closeIssue
5998
+ } ;
5999
+
6000
+
5892
6001
/***/ } ) ,
5893
6002
5894
6003
/***/ 653 :
@@ -5910,121 +6019,94 @@ exports.logWarning = log(warning);
5910
6019
5911
6020
/***/ } ) ,
5912
6021
5913
- /***/ 26 :
6022
+ /***/ 254 :
5914
6023
/***/ ( ( module , __unused_webpack_exports , __nccwpck_require__ ) => {
5915
6024
5916
6025
"use strict" ;
5917
6026
5918
- const github = __nccwpck_require__ ( 438 ) ;
5919
6027
5920
- async function getLatestRelease ( token ) {
5921
- const octokit = github . getOctokit ( token ) ;
5922
- const { owner, repo } = github . context . repo ;
5923
-
5924
- const allReleasesResp = await octokit . request ( `GET /repos/{owner}/{repo}/releases` , {
5925
- owner,
5926
- repo,
5927
- } ) ;
6028
+ const { logInfo } = __nccwpck_require__ ( 653 ) ;
6029
+ const { getLatestRelease, getUnreleasedCommits } = __nccwpck_require__ ( 26 ) ;
6030
+ const { createOrUpdateIssue, getLastOpenPendingIssue, closeIssue } = __nccwpck_require__ ( 465 ) ;
5928
6031
5929
- return allReleasesResp . data . length ? allReleasesResp . data [ 0 ] : null ;
5930
- }
6032
+ async function runAction ( token , staleDays , commitMessageLines ) {
6033
+ const latestRelease = await getLatestRelease ( token ) ;
5931
6034
5932
- async function getUnreleasedCommits ( token , latestReleaseDate , staleDays ) {
5933
- const octokit = github . getOctokit ( token ) ;
5934
- const { owner , repo } = github . context . repo ;
6035
+ if ( ! latestRelease ) {
6036
+ return logInfo ( 'Could not find latest release' ) ;
6037
+ }
5935
6038
5936
- const allCommitsResp = await octokit . request ( `GET /repos/{owner}/{repo}/commits` , {
5937
- owner,
5938
- repo,
5939
- since : latestReleaseDate ,
5940
- } ) ;
6039
+ logInfo ( `Latest release - name:${ latestRelease . name } , created:${ latestRelease . created_at } ,
6040
+ Tag:${ latestRelease . tag_name } , author:${ latestRelease . author . login } ` ) ;
5941
6041
5942
- const staleDate = new Date ( ) . getTime ( ) - ( staleDays * 24 * 60 * 60 * 1000 ) ;
6042
+ let pendingIssue = await getLastOpenPendingIssue ( token ) ;
6043
+ const unreleasedCommits = await getUnreleasedCommits (
6044
+ token ,
6045
+ latestRelease . created_at ,
6046
+ staleDays ,
6047
+ ) ;
5943
6048
5944
- for ( const commit of allCommitsResp . data ) {
5945
- const commitDate = new Date ( commit . commit . committer . date ) . getTime ( ) ;
5946
- if ( commitDate < staleDate ) {
5947
- return allCommitsResp . data ;
6049
+ if ( unreleasedCommits . length ) {
6050
+ await createOrUpdateIssue ( token , unreleasedCommits , pendingIssue , latestRelease , commitMessageLines ) ;
6051
+ } else {
6052
+ logInfo ( 'No pending commits found' ) ;
6053
+ if ( pendingIssue && Date . parse ( latestRelease . created_at ) > Date . parse ( pendingIssue . updated_at ) ) {
6054
+ await closeIssue ( token , pendingIssue . number ) ;
5948
6055
}
5949
6056
}
5950
-
5951
- return [ ] ;
5952
6057
}
5953
6058
5954
6059
module . exports = {
5955
- getLatestRelease,
5956
- getUnreleasedCommits,
6060
+ runAction,
5957
6061
} ;
5958
6062
5959
6063
5960
6064
/***/ } ) ,
5961
6065
5962
- /***/ 608 :
6066
+ /***/ 26 :
5963
6067
/***/ ( ( module , __unused_webpack_exports , __nccwpck_require__ ) => {
5964
6068
5965
6069
"use strict" ;
5966
6070
5967
6071
const github = __nccwpck_require__ ( 438 ) ;
5968
6072
5969
- async function createIssue ( token , issueTitle , issueBody , label ) {
5970
- const octokit = github . getOctokit ( token ) ;
5971
-
5972
- return octokit . issues . create ( {
5973
- ...github . context . repo ,
5974
- title : issueTitle ,
5975
- body : issueBody ,
5976
- labels : [ label ] ,
5977
- } ) ;
5978
- }
5979
-
5980
- async function getLastOpenPendingIssue ( token , latestReleaseDate , label ) {
6073
+ async function getLatestRelease ( token ) {
5981
6074
const octokit = github . getOctokit ( token ) ;
5982
6075
const { owner, repo } = github . context . repo ;
5983
6076
5984
- const pendingIssues = await octokit . request ( `GET /repos/{owner}/{repo}/issues ` , {
6077
+ const allReleasesResp = await octokit . request ( `GET /repos/{owner}/{repo}/releases/latest ` , {
5985
6078
owner,
5986
6079
repo,
5987
- since : latestReleaseDate ,
5988
- creator : 'app/github-actions' ,
5989
- state : 'open' ,
5990
- sort : 'created' ,
5991
- direction : 'desc' ,
5992
- labels : label
5993
6080
} ) ;
5994
6081
5995
- return pendingIssues . data . length ? pendingIssues . data [ 0 ] : null ;
6082
+ return allReleasesResp . data ;
5996
6083
}
5997
6084
5998
- async function updateLastOpenPendingIssue ( token , issueTitle , issueBody , issueNo ) {
6085
+ async function getUnreleasedCommits ( token , latestReleaseDate , staleDays ) {
5999
6086
const octokit = github . getOctokit ( token ) ;
6000
6087
const { owner, repo } = github . context . repo ;
6001
6088
6002
- const updatedIssue = await octokit . request ( `PATCH /repos/{owner}/{repo}/issues/ ${ issueNo } ` , {
6089
+ const allCommitsResp = await octokit . request ( `GET /repos/{owner}/{repo}/commits ` , {
6003
6090
owner,
6004
6091
repo,
6005
- title : issueTitle ,
6006
- body : issueBody
6092
+ since : latestReleaseDate ,
6007
6093
} ) ;
6008
6094
6009
- return updatedIssue . data . length ? updatedIssue . data [ 0 ] : null ;
6010
- }
6095
+ const staleDate = new Date ( ) . getTime ( ) - ( staleDays * 24 * 60 * 60 * 1000 ) ;
6011
6096
6012
- function formatCommitMessage ( fullCommitMessage , numberOfLines ) {
6013
- if ( ! numberOfLines || numberOfLines < 0 ) {
6014
- return fullCommitMessage ;
6097
+ for ( const commit of allCommitsResp . data ) {
6098
+ const commitDate = new Date ( commit . commit . committer . date ) . getTime ( ) ;
6099
+ if ( commitDate < staleDate ) {
6100
+ return allCommitsResp . data ;
6101
+ }
6015
6102
}
6016
- return fullCommitMessage
6017
- . split ( '\n' )
6018
- . slice ( 0 , numberOfLines )
6019
- . join ( '\n' )
6020
- . trim ( ) ;
6103
+
6104
+ return [ ] ;
6021
6105
}
6022
6106
6023
6107
module . exports = {
6024
- createIssue,
6025
- getLastOpenPendingIssue,
6026
- updateLastOpenPendingIssue,
6027
- formatCommitMessage,
6108
+ getLatestRelease,
6109
+ getUnreleasedCommits,
6028
6110
} ;
6029
6111
6030
6112
@@ -6185,54 +6267,16 @@ var __webpack_exports__ = {};
6185
6267
6186
6268
const core = __nccwpck_require__ ( 186 ) ;
6187
6269
const { logInfo } = __nccwpck_require__ ( 653 ) ;
6188
- const { getLatestRelease , getUnreleasedCommits } = __nccwpck_require__ ( 26 ) ;
6189
- const { createIssue , getLastOpenPendingIssue , updateLastOpenPendingIssue , formatCommitMessage } = __nccwpck_require__ ( 608 ) ;
6270
+
6271
+ const { runAction } = __nccwpck_require__ ( 254 ) ;
6190
6272
6191
6273
async function run ( ) {
6192
6274
try {
6193
6275
const token = core . getInput ( 'github-token' , { required : true } ) ;
6194
6276
const staleDays = Number ( core . getInput ( 'stale-days' ) ) ;
6195
6277
const commitMessageLines = Number ( core . getInput ( 'commit-messages-lines' ) ) ;
6196
- const latestRelease = await getLatestRelease ( token ) ;
6197
- const label = 'notify-release' ;
6198
-
6199
- if ( ! latestRelease ) {
6200
- return logInfo ( 'Could not find latest release' ) ;
6201
- }
6202
-
6203
- logInfo ( `Latest release - name:${ latestRelease . name } , created:${ latestRelease . created_at } ,
6204
- Tag:${ latestRelease . tag_name } , author:${ latestRelease . author . login } ` ) ;
6205
-
6206
- const unreleasedCommits = await getUnreleasedCommits (
6207
- token ,
6208
- latestRelease . created_at ,
6209
- staleDays ,
6210
- ) ;
6211
-
6212
- if ( unreleasedCommits . length ) {
6213
- const commitStr = unreleasedCommits . map ( ( commit ) => `Commit: ${ formatCommitMessage ( commit . commit . message , commitMessageLines ) }
6214
- Author: ${ commit . commit . author . name }
6215
6278
6216
- ` ) . join ( '' ) ;
6217
- const issueBody = `Unreleased commits have been found which are pending release, please publish the changes.
6218
-
6219
- ### Commits since the last release
6220
- ${ commitStr } ` ;
6221
- const issueTitle = 'Release pending!' ;
6222
-
6223
- const lastPendingIssue = await getLastOpenPendingIssue ( token , latestRelease . created_at , label ) ;
6224
-
6225
- if ( lastPendingIssue ) {
6226
- await updateLastOpenPendingIssue ( token , issueTitle , issueBody , lastPendingIssue . number ) ;
6227
- logInfo ( `Issue ${ lastPendingIssue . number } has been updated` ) ;
6228
- } else {
6229
- const issueNo = await createIssue ( token , issueTitle , issueBody , label ) ;
6230
- logInfo ( `New issue has been created. Issue No. - ${ JSON . stringify ( issueNo . data . number ) } ` ) ;
6231
- }
6232
-
6233
- } else {
6234
- logInfo ( 'No pending commits found' ) ;
6235
- }
6279
+ return await runAction ( token , staleDays , commitMessageLines ) ;
6236
6280
} catch ( error ) {
6237
6281
logInfo ( error . message ) ;
6238
6282
core . setFailed ( error . message ) ;
0 commit comments