Skip to content

Commit

Permalink
✨ Add .gitattributes generator
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary authored Jul 6, 2022
1 parent fc4e605 commit 66bdb6b
Showing 1 changed file with 109 additions and 57 deletions.
166 changes: 109 additions & 57 deletions src/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const generateSummary = async () => {

let fallbackIcon = "";
try {
fallbackIcon = `https://icons.duckduckgo.com/ip3/${parse(site.url).hostname}.ico`;
fallbackIcon = `https://icons.duckduckgo.com/ip3/${
parse(site.url).hostname
}.ico`;
} catch (error) {}

pageStatuses.push({
Expand Down Expand Up @@ -79,14 +81,20 @@ export const generateSummary = async () => {

const i18n = config.i18n || {};

if (readmeContent.includes(config.summaryStartHtmlComment || "<!--start: status pages-->")) {
readmeContent = `${startText}${config.summaryStartHtmlComment || "<!--start: status pages-->"}
if (
readmeContent.includes(
config.summaryStartHtmlComment || "<!--start: status pages-->"
)
) {
readmeContent = `${startText}${
config.summaryStartHtmlComment || "<!--start: status pages-->"
}
<!-- This summary is generated by Upptime (https://github.com/upptime/upptime) -->
<!-- Do not edit this manually, your changes will be overwritten -->
<!-- prettier-ignore -->
| ${i18n.url || "URL"} | ${i18n.status || "Status"} | ${i18n.history || "History"} | ${
i18n.responseTime || "Response Time"
} | ${i18n.uptime || "Uptime"} |
| ${i18n.url || "URL"} | ${i18n.status || "Status"} | ${
i18n.history || "History"
} | ${i18n.responseTime || "Response Time"} | ${i18n.uptime || "Uptime"} |
| --- | ------ | ------- | ------------- | ------ |
${pageStatuses
.map(
Expand All @@ -99,71 +107,73 @@ ${pageStatuses
: page.status === "degraded"
? i18n.degraded || "🟨 Degraded"
: i18n.down || "🟥 Down"
} | [${page.slug}.yml](https://github.com/${owner}/${repo}/commits/HEAD/history/${
} | [${
page.slug
}.yml](https://github.com/${owner}/${repo}/commits/HEAD/history/${
page.slug
}.yml) | <details><summary><img alt="${
i18n.responseTimeGraphAlt || "Response time graph"
}" src="./graphs/${page.slug}/response-time-week.png" height="20"> ${page.timeWeek}${
i18n.ms || "ms"
}</summary><br><a href="${website}/history/${page.slug}"><img alt="${
i18n.responseTime || "Response time"
} ${
}" src="./graphs/${page.slug}/response-time-week.png" height="20"> ${
page.timeWeek
}${i18n.ms || "ms"}</summary><br><a href="${website}/history/${
page.slug
}"><img alt="${i18n.responseTime || "Response time"} ${
page.time
}" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2F${owner}%2F${repo}%2FHEAD%2Fapi%2F${
page.slug
}%2Fresponse-time.json"></a><br><a href="${website}/history/${page.slug}"><img alt="${
i18n.responseTimeDay || "24-hour response time"
} ${
}%2Fresponse-time.json"></a><br><a href="${website}/history/${
page.slug
}"><img alt="${i18n.responseTimeDay || "24-hour response time"} ${
page.timeDay
}" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2F${owner}%2F${repo}%2FHEAD%2Fapi%2F${
page.slug
}%2Fresponse-time-day.json"></a><br><a href="${website}/history/${page.slug}"><img alt="${
i18n.responseTimeWeek || "7-day response time"
} ${
}%2Fresponse-time-day.json"></a><br><a href="${website}/history/${
page.slug
}"><img alt="${i18n.responseTimeWeek || "7-day response time"} ${
page.timeWeek
}" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2F${owner}%2F${repo}%2FHEAD%2Fapi%2F${
page.slug
}%2Fresponse-time-week.json"></a><br><a href="${website}/history/${page.slug}"><img alt="${
i18n.responseTimeMonth || "30-day response time"
} ${
}%2Fresponse-time-week.json"></a><br><a href="${website}/history/${
page.slug
}"><img alt="${i18n.responseTimeMonth || "30-day response time"} ${
page.timeMonth
}" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2F${owner}%2F${repo}%2FHEAD%2Fapi%2F${
page.slug
}%2Fresponse-time-month.json"></a><br><a href="${website}/history/${page.slug}"><img alt="${
i18n.responseTimeYear || "1-year response time"
} ${
}%2Fresponse-time-month.json"></a><br><a href="${website}/history/${
page.slug
}"><img alt="${i18n.responseTimeYear || "1-year response time"} ${
page.timeYear
}" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2F${owner}%2F${repo}%2FHEAD%2Fapi%2F${
page.slug
}%2Fresponse-time-year.json"></a></details> | <details><summary><a href="${website}/history/${
page.slug
}">${page.uptimeWeek}</a></summary><a href="${website}/history/${page.slug}"><img alt="${
i18n.uptime || "All-time uptime"
} ${
}">${page.uptimeWeek}</a></summary><a href="${website}/history/${
page.slug
}"><img alt="${i18n.uptime || "All-time uptime"} ${
page.uptime
}" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2F${owner}%2F${repo}%2FHEAD%2Fapi%2F${
page.slug
}%2Fuptime.json"></a><br><a href="${website}/history/${page.slug}"><img alt="${
i18n.uptimeDay || "24-hour uptime"
} ${
}%2Fuptime.json"></a><br><a href="${website}/history/${
page.slug
}"><img alt="${i18n.uptimeDay || "24-hour uptime"} ${
page.uptimeDay
}" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2F${owner}%2F${repo}%2FHEAD%2Fapi%2F${
page.slug
}%2Fuptime-day.json"></a><br><a href="${website}/history/${page.slug}"><img alt="${
i18n.uptimeWeek || "7-day uptime"
} ${
}%2Fuptime-day.json"></a><br><a href="${website}/history/${
page.slug
}"><img alt="${i18n.uptimeWeek || "7-day uptime"} ${
page.uptimeWeek
}" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2F${owner}%2F${repo}%2FHEAD%2Fapi%2F${
page.slug
}%2Fuptime-week.json"></a><br><a href="${website}/history/${page.slug}"><img alt="${
i18n.uptimeMonth || "30-day uptime"
} ${
}%2Fuptime-week.json"></a><br><a href="${website}/history/${
page.slug
}"><img alt="${i18n.uptimeMonth || "30-day uptime"} ${
page.uptimeMonth
}" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2F${owner}%2F${repo}%2FHEAD%2Fapi%2F${
page.slug
}%2Fuptime-month.json"></a><br><a href="${website}/history/${page.slug}"><img alt="${
i18n.uptimeYear || "1-year uptime"
} ${
}%2Fuptime-month.json"></a><br><a href="${website}/history/${
page.slug
}"><img alt="${i18n.uptimeYear || "1-year uptime"} ${
page.uptimeYear
}" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2F${owner}%2F${repo}%2FHEAD%2Fapi%2F${
page.slug
Expand All @@ -190,7 +200,10 @@ ${config.summaryEndHtmlComment || "<!--end: status pages-->"}${endText}`;
return `${line}\n\nWith [Upptime](https://upptime.js.org), you can get your own unlimited and free uptime monitor and status page, powered entirely by a GitHub repository. We use [Issues](https://github.com/${config.owner}/${config.repo}/issues) as incident reports, [Actions](https://github.com/${config.owner}/${config.repo}/actions) as uptime monitors, and [Pages](${website}) for the status page.`;
return line;
})
.filter((line) => !line.startsWith(`## [📈 ${i18n.liveStatus || "Live Status"}]`))
.filter(
(line) =>
!line.startsWith(`## [📈 ${i18n.liveStatus || "Live Status"}]`)
)
.join("\n");

// Remove default documentation
Expand All @@ -211,13 +224,21 @@ ${config.summaryEndHtmlComment || "<!--end: status pages-->"}${endText}`;
readmeContent.includes("<!--start: description-->")
) {
try {
const org = await octokit.users.getByUsername({ username: config.owner });
name = `[${org.data.name || config.owner}](${org.data.blog || website})`;
const org = await octokit.users.getByUsername({
username: config.owner,
});
name = `[${org.data.name || config.owner}](${
org.data.blog || website
})`;
} catch (error) {}

// Remove Koj description
const descriptionStartText = readmeContent.split("<!--start: description-->")[0];
const descriptionEndText = readmeContent.split("<!--end: description-->")[1];
const descriptionStartText = readmeContent.split(
"<!--start: description-->"
)[0];
const descriptionEndText = readmeContent.split(
"<!--end: description-->"
)[1];
if (readmeContent.includes("<!--start: description-->"))
readmeContent = `${descriptionStartText}This repository contains the open-source uptime monitor and status page for ${name}, powered by [Upptime](https://github.com/upptime/upptime).${descriptionEndText}`;

Expand Down Expand Up @@ -254,7 +275,10 @@ ${config.summaryEndHtmlComment || "<!--end: status pages-->"}${endText}`;
.replace("[", "")}, powered by @upptime`,
});
console.log("Current topics are", repoInfo.data.topics);
if (!(repoInfo.data.topics || []).includes("upptime") && !config.skipTopicsUpdate)
if (
!(repoInfo.data.topics || []).includes("upptime") &&
!config.skipTopicsUpdate
)
await octokit.repos.replaceAllTopics({
owner,
repo,
Expand All @@ -267,11 +291,17 @@ ${config.summaryEndHtmlComment || "<!--end: status pages-->"}${endText}`;
});
console.log(
"Possibly updated to to",
[...(repoInfo.data.topics || []), "uptime-monitor", "status-page", "upptime"].filter(
(value, index, array) => array.indexOf(value) === index
)
[
...(repoInfo.data.topics || []),
"uptime-monitor",
"status-page",
"upptime",
].filter((value, index, array) => array.indexOf(value) === index)
);
console.log(
"Topics are",
(await octokit.repos.get({ owner, repo })).data.topics
);
console.log("Topics are", (await octokit.repos.get({ owner, repo })).data.topics);
if (!repoInfo.data.homepage && !config.skipHomepageUpdate)
await octokit.repos.update({
owner,
Expand Down Expand Up @@ -302,7 +332,15 @@ ${config.summaryEndHtmlComment || "<!--end: status pages-->"}${endText}`;
})
.join("\n");

await writeFile(join(".", "README.md"), format(readmeContent, { parser: "markdown" }));
await writeFile(
join(".", "README.md"),
format(readmeContent, { parser: "markdown" })
);
await writeFile(
join(".", ".gitattributes"),
"# Markdown\n*.md linguist-detectable=true\n*.md linguist-documentation=false\n\n# JSON\n*.json linguist-detectable=true\n\n# YAML\n*.yml linguist-detectable=true\n"
);

commit(
(config.commitMessages || {}).readmeContent ||
":pencil: Update summary in README [skip ci] [upptime]",
Expand All @@ -311,19 +349,28 @@ ${config.summaryEndHtmlComment || "<!--end: status pages-->"}${endText}`;
);

// If there are any old workflows left, fix them
const workflows = (await readdir(join(".", ".github", "workflows"))).filter((i) =>
i.endsWith(".yml")
const workflows = (await readdir(join(".", ".github", "workflows"))).filter(
(i) => i.endsWith(".yml")
);
for await (const workflow of workflows) {
const content = await readFile(join(".", ".github", "workflows", workflow), "utf8");
const newContent = content.replace("actions/[email protected]", "actions/[email protected]");
const content = await readFile(
join(".", ".github", "workflows", workflow),
"utf8"
);
const newContent = content.replace(
"actions/[email protected]",
"actions/[email protected]"
);
if (content !== newContent) {
console.log("Updating workflow", workflow);
await writeFile(join(".", ".github", "workflows", workflow), newContent);
}
}

await writeFile(join(".", "history", "summary.json"), JSON.stringify(pageStatuses, null, 2));
await writeFile(
join(".", "history", "summary.json"),
JSON.stringify(pageStatuses, null, 2)
);
commit(
(config.commitMessages || {}).summaryJson ||
":card_file_box: Update status summary [skip ci] [upptime]",
Expand All @@ -343,12 +390,17 @@ ${config.summaryEndHtmlComment || "<!--end: status pages-->"}${endText}`;
labels: "status",
per_page: 10,
});
console.log("Found recently closed issues", issuesRecentlyClosed.data.length);
console.log(
"Found recently closed issues",
issuesRecentlyClosed.data.length
);
for await (const issue of issuesRecentlyClosed.data) {
if (
issue.closed_at &&
// If this issue was closed within 15 minutes
new Date(issue.closed_at).getTime() - new Date(issue.created_at).getTime() < 900000 &&
new Date(issue.closed_at).getTime() -
new Date(issue.created_at).getTime() <
900000 &&
// It has 1 comment (the default Upptime one)
issue.comments === 1
) {
Expand Down

0 comments on commit 66bdb6b

Please sign in to comment.