Skip to content

Commit

Permalink
Adding time delta to the 'resolved' comment (#222)
Browse files Browse the repository at this point in the history
* added function in to measure time issue was open

* adding function

* Added timedelta in issue comment

* Update src/update.ts

Co-authored-by: Anand Chowdhary <github@anandchowdhary.com>

---------

Co-authored-by: Peter van Doorn <pvandoorn@bunq.com>
Co-authored-by: Anand Chowdhary <github@anandchowdhary.com>
  • Loading branch information
3 people authored Aug 18, 2023
1 parent dddb1eb commit 51cca2f
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ import { generateSummary } from "./summary";

const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

function getHumanReadableTimeDifference(startTime) {

Check failure on line 22 in src/update.ts

View workflow job for this annotation

GitHub Actions / Build and Publish

Parameter 'startTime' implicitly has an 'any' type.
const now = new Date();
const deltaMilliseconds = now - startTime;

Check failure on line 24 in src/update.ts

View workflow job for this annotation

GitHub Actions / Build and Publish

The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
const seconds = Math.floor(deltaMilliseconds / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);

if (days > 0) {
return `${days} days, ${hours % 24} hours, ${minutes % 60} minutes`;
} else if (hours > 0) {
return `${hours} hours, ${minutes % 60} minutes`;
} else if (minutes > 0) {
return `${minutes} minutes`;
} else {
return `${seconds} seconds`;
}
}


export const update = async (shouldCommit = false) => {
if (!(await shouldContinue())) return;
await mkdirp("history");
Expand Down Expand Up @@ -402,17 +422,20 @@ generator: Upptime <https://github.com/upptime/upptime>
repo,
issue_number: issues.data[0].number,
});
await octokit.issues.createComment({
await octokit.issues.createComment({
owner,
repo,
issue_number: issues.data[0].number,
body: `**Resolved:** ${site.name} ${issues.data[0].title.includes("degraded")
body: `**Resolved:** ${site.name} ${
issues.data[0].title.includes("degraded")
? "performance has improved"
: "is back up"
} in [\`${lastCommitSha.substr(
0,
7
)}\`](https://github.com/${owner}/${repo}/commit/${lastCommitSha}).`,
} in [\`${lastCommitSha.substr(
0,
7
)}\`](https://github.com/${owner}/${repo}/commit/${lastCommitSha}) after ${getHumanReadableTimeDifference(
startTime
)}.`,
});
console.log("Created comment in issue");
await octokit.issues.update({
Expand Down

0 comments on commit 51cca2f

Please sign in to comment.