1111
1212//@ts -check
1313
14- /*
15- * this file contains only 3 functions from the original ci.js:
14+ /*
15+ * this file contains only 3 functions from the original ci.js:
1616 * extractCommandFromComment, reactToComment, startWorkflow.
1717 * original ci.js file can be found here:
1818 * https://github.com/deckhouse/deckhouse/blob/main/.github/scripts/js/ci.js
@@ -32,18 +32,18 @@ const extractCommandFromComment = (comment) => {
3232 if ( lines . length < 1 ) {
3333 return { 'err' : 'first line is not a slash command' }
3434 }
35-
35+
3636 // Search for user command in the first line of the comment.
3737 // User command is a command and a tag name.
3838 const argv = lines [ 0 ] . split ( / \s + / ) ;
39-
39+
4040 if ( ! / ^ \/ [ a - z \d _ \- \/ . , ] + $ / . test ( argv [ 0 ] ) ) {
4141 return { 'err' : 'not a slash command in the first line' } ;
4242 }
43-
43+
4444 return { argv, lines}
4545} ;
46-
46+
4747module . exports . extractCommandFromComment = extractCommandFromComment ;
4848
4949/**
@@ -88,7 +88,7 @@ const getClusterUser = async ({context, core, userClusterLabels}) => {
8888 return userClusterLabels [ userLabelsInPR ] . id
8989} ;
9090module . exports . getClusterUser = getClusterUser ;
91-
91+
9292/**
9393 * Start workflow using workflow_dispatch event.
9494 *
@@ -103,7 +103,7 @@ module.exports.getClusterUser = getClusterUser;
103103 */
104104const startWorkflow = async ( { github, context, core, workflow_id, ref, inputs } ) => {
105105 core . info ( `Start workflow '${ workflow_id } ' using ref '${ ref } ' and inputs ${ JSON . stringify ( inputs ) } .` ) ;
106-
106+
107107 let response = null
108108 try {
109109 response = await github . rest . actions . createWorkflowDispatch ( {
@@ -116,13 +116,38 @@ const startWorkflow = async ({ github, context, core, workflow_id, ref, inputs }
116116 } catch ( error ) {
117117 return core . setFailed ( `Error triggering workflow_dispatch event: ${ dumpError ( error ) } ` )
118118 }
119-
119+
120120 core . debug ( `status: ${ response . status } ` ) ;
121121 core . debug ( `workflow dispatch response: ${ JSON . stringify ( response ) } ` ) ;
122-
122+
123123 if ( response . status !== 204 ) {
124124 return core . setFailed ( `Error triggering workflow_dispatch event for '${ workflow_id } '. createWorkflowDispatch response: ${ JSON . stringify ( response ) } ` ) ;
125125 }
126126 return core . info ( `Workflow '${ workflow_id } ' started successfully` ) ;
127127} ;
128- module . exports . startWorkflow = startWorkflow ;
128+ module . exports . startWorkflow = startWorkflow ;
129+
130+ /**
131+ * Removes a specified label from a GitHub issue or pull request.
132+ * @param {{ github: any, context: any, labels: any[], labelToRemove: string } } params - The parameters for the function.
133+ * @returns {Promise<boolean> } A promise that resolves to true if the label was removed, false if it was not found.
134+ */
135+ const removeLabel = async ( { github, context, labels, labelToRemove } ) => {
136+ const issueNumber = context . issue . number ;
137+ const owner = context . repo . owner ;
138+ const repo = context . repo . repo ;
139+ if ( labels . some ( label => label . name === labelToRemove ) ) {
140+ await github . rest . issues . removeLabel ( {
141+ owner,
142+ repo,
143+ issue_number : issueNumber ,
144+ name : labelToRemove ,
145+ } ) ;
146+ console . log ( `Removed label '${ labelToRemove } ' from PR #${ issueNumber } ` ) ;
147+ return true ;
148+ } else {
149+ console . log ( `Label '${ labelToRemove } ' not found on PR #${ issueNumber } ` ) ;
150+ return false ;
151+ }
152+ }
153+ module . exports . removeLabel = removeLabel ;
0 commit comments