@@ -6278,7 +6278,7 @@ const ALLREACTIONS = [
62786278 "eyes" ,
62796279] ;
62806280
6281- const { dealInput } = __webpack_require__ ( 6254 ) ;
6281+ const { dealInput, testDuplicate } = __webpack_require__ ( 6254 ) ;
62826282
62836283const token = core . getInput ( 'token' ) ;
62846284const octokit = new Octokit ( { auth : `token ${ token } ` } ) ;
@@ -6407,22 +6407,37 @@ async function doMarkDuplicate (owner, repo, labels) {
64076407 core . info ( `This actions only support on 'issue_comment'!` ) ;
64086408 return false ;
64096409 }
6410- const duplicateCommand = core . getInput ( "duplicate-command" ) || '/d' ;
6410+ if ( context . payload . action != 'created' ) {
6411+ core . info ( `This actions only support on 'issue_comment' created!` ) ;
6412+ return false ;
6413+ }
6414+
6415+ const duplicateCommand = core . getInput ( "duplicate-command" ) ;
64116416 const duplicateLabels = core . getInput ( "duplicate-labels" ) ;
6417+ const closeIssue = core . getInput ( "close-issue" ) ;
64126418
64136419 const commentId = context . payload . comment . id ;
64146420 const commentBody = context . payload . comment . body ;
64156421 const issueNumber = context . payload . issue . number ;
64166422
6417- if ( commentBody . startsWith ( duplicateCommand ) && commentBody . split ( ' ' ) [ 0 ] == duplicateCommand ) {
6418- const nextBody = commentBody . replace ( duplicateCommand , 'Duplicate of' ) ;
6419- await doUpdateComment ( owner , repo , commentId , nextBody , 'replace' , true ) ;
6423+ const ifCommandInput = ! ! duplicateCommand ;
6424+
6425+ if ( ( ifCommandInput && commentBody . startsWith ( duplicateCommand ) && commentBody . split ( ' ' ) [ 0 ] == duplicateCommand ) || testDuplicate ( commentBody ) ) {
6426+ if ( ifCommandInput ) {
6427+ const nextBody = commentBody . replace ( duplicateCommand , 'Duplicate of' ) ;
6428+ await doUpdateComment ( owner , repo , commentId , nextBody , 'replace' , true ) ;
6429+ } else if ( contents ) {
6430+ await doCreateCommentContent ( owner , repo , commentId , dealInput ( contents ) ) ;
6431+ }
64206432 if ( duplicateLabels ) {
64216433 await doAddLabels ( owner , repo , issueNumber , duplicateLabels ) ;
64226434 }
64236435 if ( labels ) {
64246436 await doSetLabels ( owner , repo , issueNumber , labels ) ;
64256437 }
6438+ if ( closeIssue == 'true' ) {
6439+ await doCloseIssue ( owner , repo , issueNumber ) ;
6440+ }
64266441 } else {
64276442 core . info ( `This comment body should start whith 'duplicate-command'` ) ;
64286443 }
@@ -6905,13 +6920,27 @@ function dealInput (para) {
69056920 return arr ;
69066921} ;
69076922
6908- function matchKeyword ( content , keywords ) {
6923+ function matchKeyword ( content , keywords ) {
69096924 return keywords . find ( item => content . toLowerCase ( ) . includes ( item ) ) ;
69106925} ;
69116926
6927+ function testDuplicate ( body ) {
6928+ if ( ! body || ! body . startsWith ( 'Duplicate of' ) ) {
6929+ return false
6930+ }
6931+
6932+ let arr = body . split ( ' ' ) ;
6933+ if ( arr [ 0 ] == 'Duplicate' && arr [ 1 ] == 'of' ) {
6934+ return true ;
6935+ } else {
6936+ return false ;
6937+ }
6938+ } ;
6939+
69126940module . exports = {
69136941 dealInput,
69146942 matchKeyword,
6943+ testDuplicate,
69156944} ;
69166945
69176946
0 commit comments