11const fs = require ( 'fs' ) ;
22const { parse } = require ( 'yaml' ) ;
3+ const { Octokit } = require ( '@octokit/rest' ) ;
34
4- module . exports = async ( { github, context, core } ) => {
5- // Extract component name from label
6- const labelName = context . payload . label . name ;
5+ async function main ( ) {
6+ // Get inputs from environment
7+ const token = process . env . GITHUB_TOKEN ;
8+ const labelName = process . env . LABEL_NAME ;
9+ const issueNumber = parseInt ( process . env . ISSUE_NUMBER ) ;
10+ const owner = process . env . REPO_OWNER ;
11+ const repo = process . env . REPO_NAME ;
712
813 if ( ! labelName . startsWith ( 'component:' ) ) {
9- core . setFailed ( 'Label does not match expected pattern' ) ;
10- return ;
14+ console . error ( 'Label does not match expected pattern' ) ;
15+ process . exit ( 1 ) ;
1116 }
1217
1318 const componentName = labelName . replace ( 'component:' , '' ) ;
@@ -18,35 +23,40 @@ module.exports = async ({ github, context, core }) => {
1823 const data = parse ( yamlContent ) ;
1924
2025 if ( ! data || ! data . components ) {
21- core . setFailed ( 'Invalid component_owners.yml structure' ) ;
22- return ;
26+ console . error ( 'Invalid component_owners.yml structure' ) ;
27+ process . exit ( 1 ) ;
2328 }
2429
2530 const components = data . components ;
2631
2732 if ( ! ( componentName in components ) ) {
28- core . setFailed ( `Component '${ componentName } ' not found in component_owners.yml` ) ;
29- return ;
33+ console . error ( `Component '${ componentName } ' not found in component_owners.yml` ) ;
34+ process . exit ( 1 ) ;
3035 }
3136
3237 const owners = components [ componentName ] ;
3338
3439 if ( ! owners || owners . length === 0 ) {
35- core . setFailed ( `No owners found for component '${ componentName } '` ) ;
36- return ;
40+ console . error ( `No owners found for component '${ componentName } '` ) ;
41+ process . exit ( 1 ) ;
3742 }
3843
3944 console . log ( `Found owners: ${ owners . join ( ', ' ) } ` ) ;
4045
4146 // Assign the issue to the owners
42- const issueNumber = context . payload . issue . number ;
47+ const octokit = new Octokit ( { auth : token } ) ;
4348
44- await github . rest . issues . addAssignees ( {
45- owner : context . repo . owner ,
46- repo : context . repo . repo ,
49+ await octokit . rest . issues . addAssignees ( {
50+ owner,
51+ repo,
4752 issue_number : issueNumber ,
4853 assignees : owners
4954 } ) ;
5055
5156 console . log ( `Successfully assigned issue #${ issueNumber } to ${ owners . join ( ', ' ) } ` ) ;
52- } ;
57+ }
58+
59+ main ( ) . catch ( error => {
60+ console . error ( error ) ;
61+ process . exit ( 1 ) ;
62+ } ) ;
0 commit comments