Skip to content

Commit

Permalink
slight refactor
Browse files Browse the repository at this point in the history
Signed-off-by: IThundxr <[email protected]>
  • Loading branch information
IThundxr committed Jul 26, 2023
1 parent 11a233b commit dfce793
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/webserver/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export const handleWebhook = (client: Client, req: Request, res: Response) => {
actionPush(req);
}

if (req.body.action === 'in_progress') {
if (req.body.action === 'requested') {
// this is run on the workflow_run webhook event
// when the workflow is started
// when the workflow is requested
if (isBuildRun(req)) {
actionStart(client, req);
}
Expand Down Expand Up @@ -59,8 +59,7 @@ const actionStart = async (client: Client, req: Request) => {
const unix_started_at = Math.floor(
Date.parse(workflow_run.run_started_at) / 1000
);
const run_number = await getRunNumber(workflow_run.url);
const version = await getVersion(workflow_run.url);
const version = await getVersion(workflow_run.url, workflow_run.run_number);

const commitString = generateCommitsString(workflow_run.head_sha);

Expand All @@ -72,7 +71,7 @@ const actionStart = async (client: Client, req: Request) => {
})
.setDescription(
`## Build <t:${unix_started_at}:R>
Status: Build is running for **#${run_number}** ${process.env.LOADING_EMOJI}
Status: Build is running for **#${workflow_run.run_number}** ${process.env.LOADING_EMOJI}
Version: ${version}
${commitString}
`
Expand Down Expand Up @@ -100,8 +99,7 @@ const actionCompleted = async (client: Client, req: Request) => {
const unix_started_at = Math.floor(
Date.parse(workflow_run.run_started_at) / 1000
);
const run_number = await getRunNumber(workflow_run.url);
const version = await getVersion(workflow_run.url);
const version = await getVersion(workflow_run.url, workflow_run.run_number);

const status =
workflow_run.conclusion === 'success'
Expand Down Expand Up @@ -134,7 +132,7 @@ const actionCompleted = async (client: Client, req: Request) => {
})
.setDescription(
`## Build <t:${unix_started_at}:R>
Status: **${status} #${run_number}** in ${timeTaken}
Status: **${status} #${workflow_run.run_number}** in ${timeTaken}
Version: ${version}
${commitString}
`
Expand Down Expand Up @@ -197,13 +195,7 @@ const getTimeTaken = (time: number) => {
return timeTaken;
};

const getRunNumber = async (url: URL) => {
const request = await fetch(url);
const data = await request.json();
return data.run_number;
};

const getVersion = async (apiurl: URL) => {
const getVersion = async (apiurl: URL, run_number: string) => {
const runDataRequest = await fetch(apiurl);
const runData = await runDataRequest.json();

Expand All @@ -220,9 +212,7 @@ const getVersion = async (apiurl: URL) => {
if (modVersionLine && minecraftVersionLine) {
const modVersion = modVersionLine.split('=')[1].trim();
const minecraftVersion = minecraftVersionLine.split('=')[1].trim();
return `${modVersion}-mc${minecraftVersion}.${await getRunNumber(
apiurl
)}`;
return `${modVersion}-mc${minecraftVersion}.${run_number}`;
} else {
return "Couldn't find version";
}
Expand Down

0 comments on commit dfce793

Please sign in to comment.