Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Only seeing "in progress" status #36

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9009d45
Reverting changes
Apr 14, 2021
140d8db
'testing changes
Apr 14, 2021
8aff49a
Adding a new way to set card current status. Right now we can set thi…
Apr 14, 2021
124c5ee
Adding action.yml modification
Apr 14, 2021
1d19580
Reverting changes, adding yarn.lock to git igonore and fixing up the …
Apr 14, 2021
09a12e4
Removing reverse
Apr 14, 2021
1adf066
Removing skipped status
Apr 14, 2021
c6a00c6
Removing skipped status
Apr 14, 2021
f7319f1
Removing skipped status
Apr 14, 2021
370a443
testing
Apr 14, 2021
968b3c3
testing
Apr 14, 2021
22060dd
testing
Apr 14, 2021
dd5cfdb
testing
Apr 14, 2021
ad6fe94
testing
Apr 14, 2021
0fedb24
testing
Apr 14, 2021
9219a4c
testing
Apr 15, 2021
6aa97c5
testing
Apr 15, 2021
bd09431
testing
Apr 15, 2021
28cef9f
testing
Apr 15, 2021
08edf24
testing
Apr 15, 2021
3f647a4
testing
Apr 15, 2021
b03ff76
testing
Apr 15, 2021
3d1b083
testing
Apr 15, 2021
0b4a681
testing
Apr 15, 2021
611b8a7
testing
Apr 21, 2021
ece30a3
testing
Apr 22, 2021
e042fec
testing
Apr 22, 2021
726b2cf
testing
Apr 22, 2021
16d0740
testing
Apr 22, 2021
492b88d
testing
Apr 22, 2021
15f76a4
testing
Apr 22, 2021
d39e935
testing
Apr 22, 2021
ea4361f
testing
Apr 22, 2021
8f4ce3a
testing
Apr 22, 2021
e640b39
testing
Apr 22, 2021
5e2655c
testing
Apr 22, 2021
5cbe48a
testing
Apr 22, 2021
807259f
Merge pull request #2 from ppbs2/develop
Apr 22, 2021
a67d9ee
removing logs and fixing up issue 33
Apr 22, 2021
e07e25f
removing logs and fixing up issue 33
Apr 22, 2021
19bbed9
removing unused imports
Apr 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
.DS_Store
.DS_Store
yarn.lock
package-lock.json
2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/post/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ try {
const workflowRunStatus = await getWorkflowRunStatus();
if (
(showCardOnExit && !showCardOnFailure) ||
(showCardOnFailure && workflowRunStatus.conclusion !== "success")
(showCardOnFailure && workflowRunStatus?.conclusion !== "success")
) {
formatAndNotify(
"exit",
workflowRunStatus.conclusion,
workflowRunStatus.elapsedSeconds
workflowRunStatus?.conclusion,
workflowRunStatus?.elapsedSeconds
);
} else {
info("Configured to not show card upon job exit.");
Expand Down
70 changes: 41 additions & 29 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { WebhookBody, PotentialAction } from "./models";
import { formatCompactLayout } from "./layouts/compact";
import { formatCozyLayout } from "./layouts/cozy";
import { formatCompleteLayout } from "./layouts/complete";
import { CONCLUSION_THEMES } from "./constants";

export function escapeMarkdownTokens(text: string) {
return text
Expand Down Expand Up @@ -96,34 +95,47 @@ export async function getWorkflowRunStatus() {
run_id: parseInt(runInfo.runId || "1"),
});

const job = workflowJobs.data.jobs.find(
(job: Octokit.ActionsListJobsForWorkflowRunResponseJobsItem) =>
job.name === process.env.GITHUB_JOB
);

let lastStep;
const stoppedStep = job?.steps.find(
(step: Octokit.ActionsListJobsForWorkflowRunResponseJobsItemStepsItem) =>
step.conclusion === "failure" ||
step.conclusion === "timed_out" ||
step.conclusion === "cancelled" ||
step.conclusion === "action_required"
);

if (stoppedStep) {
lastStep = stoppedStep;
} else {
lastStep = job?.steps
.reverse()
.find(
(
step: Octokit.ActionsListJobsForWorkflowRunResponseJobsItemStepsItem
) => step.status === "completed"
);
}
let lastStep = {} as Octokit.ActionsListJobsForWorkflowRunResponseJobsItemStepsItem
let jobStartDate

/**
* We have to verify all jobs steps. We don't know
* if users are using multiple jobs or not. Btw,
* we don't need to check if GITHUB_JOB env is the
* same of the Octokit job name, because it is different.
*
* @note We are using a quadratic way to search all steps.
* But we have just a few elements, so this is not
* a performance issue
*
* The conclusion steps, according to the documentation, are:
* <success>, <cancelled>, <failure> and <skipped>
*/
let abort = false
for(let job of workflowJobs.data.jobs) {
for(let step of job.steps) {
// check if current step still running
if (step.completed_at !== null) {
lastStep = step
jobStartDate = job.started_at
// Some step/job has failed. Get out from here.
if (step?.conclusion !== "success" && step?.conclusion !== "skipped") {
abort = true
break
}
/**
* If nothing has failed, so we have a success scenario
* @note ignoring skipped cases.
*/
lastStep.conclusion = "success"
}
}
// // Some step/job has failed. Get out from here.
if (abort) break
}
const startTime = moment(jobStartDate, moment.ISO_8601);
const endTime = moment(lastStep?.completed_at, moment.ISO_8601);

const startTime = moment(job?.started_at, moment.ISO_8601);
const endTime = moment(lastStep?.completed_at, moment.ISO_8601);
return {
elapsedSeconds: endTime.diff(startTime, "seconds"),
conclusion: lastStep?.conclusion,
Expand Down Expand Up @@ -167,4 +179,4 @@ export function renderActions(statusUrl: string, diffUrl: string) {
}
}
return actions;
}
}