@@ -21,7 +21,7 @@ export async function issueClosed(context: Context) {
21
21
const pullRequestComments = await getPullRequestComments ( context , owner , repository , issueNumber ) ;
22
22
const repoCollaborators = await getCollaboratorsForRepo ( context ) ;
23
23
24
- await dispatchWorkflow ( owner , "ubiquibot-config" , "compute.yml" , {
24
+ await dispatchWorkflow ( context , owner , "ubiquibot-config" , "compute.yml" , {
25
25
eventName : "issueClosed" ,
26
26
secretToken : process . env . GITHUB_TOKEN ,
27
27
owner,
@@ -39,18 +39,20 @@ export async function issueClosed(context: Context) {
39
39
supabaseKey : env . SUPABASE_KEY ,
40
40
} ) ,
41
41
} ) ;
42
-
43
- return " Please wait until we get the result." ;
42
+ const logger = Runtime . getState ( ) . logger ;
43
+ return logger . info ( "Delegating compute. Please wait for results." ) ;
44
44
}
45
45
46
- async function dispatchWorkflow ( owner : string , repo : string , workflowId : string , inputs : any ) {
46
+ async function dispatchWorkflow ( context : Context , owner : string , repo : string , workflowId : string , inputs : any ) {
47
+ const response = await context . octokit . repos . get ( { owner, repo } ) ;
48
+ const defaultBranch = response . data . default_branch ;
47
49
const res = await fetch ( `https://api.github.com/repos/${ owner } /${ repo } /actions/workflows/${ workflowId } /dispatches` , {
48
50
method : "POST" ,
49
51
headers : {
50
52
Authorization : `Bearer ${ process . env . GITHUB_TOKEN } ` ,
51
53
Accept : "application/vnd.github.v3+json" ,
52
54
} ,
53
- body : JSON . stringify ( { ref : "master" , inputs } ) ,
55
+ body : JSON . stringify ( { ref : defaultBranch , inputs } ) ,
54
56
} ) ;
55
57
if ( res . status !== 204 ) {
56
58
const errorMessage = await res . text ( ) ;
@@ -104,14 +106,14 @@ async function preflightChecks({ issue, issueComments, context }: PreflightCheck
104
106
105
107
function checkIfPermitsAlreadyPosted ( context : Context , botComments : Comment [ ] ) {
106
108
botComments . forEach ( ( comment ) => {
107
- const parsed = structuredMetadata . parse ( comment . body ) ;
108
- if ( parsed ) {
109
- console . trace ( { parsed } ) ;
110
- if ( parsed . caller === "generatePermits" ) {
111
- // in the comment metadata we store what function rendered the comment
112
- console . trace ( { parsed } ) ;
113
- throw context . logger . error ( "Permit already posted" ) ;
114
- }
109
+ const botComment = structuredMetadata . parse ( comment . body ) ;
110
+ // if (botComment) {
111
+ // console.trace({ parsed: botComment });
112
+ if ( botComment ?. className === "Permits" ) {
113
+ // in the comment metadata we store what function rendered the comment
114
+ console . trace ( { parsed : botComment } ) ;
115
+ throw context . logger . error ( "Permit already posted" ) ;
115
116
}
117
+ // }
116
118
} ) ;
117
119
}
0 commit comments