Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit db5ee8f

Browse files
committed
fix: default branch in dispatchWorkflow
1 parent b1cc46f commit db5ee8f

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/handlers/comment/handlers/issue/issue-closed.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function issueClosed(context: Context) {
2121
const pullRequestComments = await getPullRequestComments(context, owner, repository, issueNumber);
2222
const repoCollaborators = await getCollaboratorsForRepo(context);
2323

24-
await dispatchWorkflow(owner, "ubiquibot-config", "compute.yml", {
24+
await dispatchWorkflow(context, owner, "ubiquibot-config", "compute.yml", {
2525
eventName: "issueClosed",
2626
secretToken: process.env.GITHUB_TOKEN,
2727
owner,
@@ -39,18 +39,20 @@ export async function issueClosed(context: Context) {
3939
supabaseKey: env.SUPABASE_KEY,
4040
}),
4141
});
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.");
4444
}
4545

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;
4749
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}/actions/workflows/${workflowId}/dispatches`, {
4850
method: "POST",
4951
headers: {
5052
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
5153
Accept: "application/vnd.github.v3+json",
5254
},
53-
body: JSON.stringify({ ref: "master", inputs }),
55+
body: JSON.stringify({ ref: defaultBranch, inputs }),
5456
});
5557
if (res.status !== 204) {
5658
const errorMessage = await res.text();
@@ -104,14 +106,14 @@ async function preflightChecks({ issue, issueComments, context }: PreflightCheck
104106

105107
function checkIfPermitsAlreadyPosted(context: Context, botComments: Comment[]) {
106108
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");
115116
}
117+
// }
116118
});
117119
}

src/types/payload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export enum IssueType {
4646

4747
export enum StateReason {
4848
COMPLETED = "completed",
49-
// NOT_PLANNED = "not_planned",
50-
// REOPENED = "reopened",
49+
NOT_PLANNED = "not_planned", // these are all used at runtime, not necessarily in the code.
50+
REOPENED = "reopened",
5151
}
5252

5353
const userSchema = Type.Object({

0 commit comments

Comments
 (0)