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

Commit

Permalink
fix: default branch in dispatchWorkflow
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Nov 27, 2023
1 parent b1cc46f commit db5ee8f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
28 changes: 15 additions & 13 deletions src/handlers/comment/handlers/issue/issue-closed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function issueClosed(context: Context) {
const pullRequestComments = await getPullRequestComments(context, owner, repository, issueNumber);
const repoCollaborators = await getCollaboratorsForRepo(context);

await dispatchWorkflow(owner, "ubiquibot-config", "compute.yml", {
await dispatchWorkflow(context, owner, "ubiquibot-config", "compute.yml", {
eventName: "issueClosed",
secretToken: process.env.GITHUB_TOKEN,
owner,
Expand All @@ -39,18 +39,20 @@ export async function issueClosed(context: Context) {
supabaseKey: env.SUPABASE_KEY,
}),
});

return "Please wait until we get the result.";
const logger = Runtime.getState().logger;
return logger.info("Delegating compute. Please wait for results.");
}

async function dispatchWorkflow(owner: string, repo: string, workflowId: string, inputs: any) {
async function dispatchWorkflow(context: Context, owner: string, repo: string, workflowId: string, inputs: any) {
const response = await context.octokit.repos.get({ owner, repo });
const defaultBranch = response.data.default_branch;
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}/actions/workflows/${workflowId}/dispatches`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
Accept: "application/vnd.github.v3+json",
},
body: JSON.stringify({ ref: "master", inputs }),
body: JSON.stringify({ ref: defaultBranch, inputs }),
});
if (res.status !== 204) {
const errorMessage = await res.text();
Expand Down Expand Up @@ -104,14 +106,14 @@ async function preflightChecks({ issue, issueComments, context }: PreflightCheck

function checkIfPermitsAlreadyPosted(context: Context, botComments: Comment[]) {
botComments.forEach((comment) => {
const parsed = structuredMetadata.parse(comment.body);
if (parsed) {
console.trace({ parsed });
if (parsed.caller === "generatePermits") {
// in the comment metadata we store what function rendered the comment
console.trace({ parsed });
throw context.logger.error("Permit already posted");
}
const botComment = structuredMetadata.parse(comment.body);
// if (botComment) {
// console.trace({ parsed: botComment });
if (botComment?.className === "Permits") {
// in the comment metadata we store what function rendered the comment
console.trace({ parsed: botComment });
throw context.logger.error("Permit already posted");
}
// }
});
}
4 changes: 2 additions & 2 deletions src/types/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export enum IssueType {

export enum StateReason {
COMPLETED = "completed",
// NOT_PLANNED = "not_planned",
// REOPENED = "reopened",
NOT_PLANNED = "not_planned", // these are all used at runtime, not necessarily in the code.
REOPENED = "reopened",
}

const userSchema = Type.Object({
Expand Down

0 comments on commit db5ee8f

Please sign in to comment.