Skip to content

Commit

Permalink
🐛 Use workflow owner/repo
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 2, 2020
1 parent a4d2d5f commit eeecfef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { UpptimeConfig } from "./interfaces";

export const generateSummary = async () => {
const config = safeLoad(await readFile(join(".", ".upptimerc.yml"), "utf8")) as UpptimeConfig;
const owner = config.owner;
const repo = config.repo;
const [owner, repo] = (process.env.GITHUB_REPOSITORY || "").split("/");

const octokit = new Octokit({
auth: config.PAT || process.env.GH_PAT || process.env.GITHUB_TOKEN,
Expand Down Expand Up @@ -122,7 +121,7 @@ ${pageStatuses
}

if (owner !== "upptime" && repo !== "upptime") {
let website = `https://${config.owner}.github.io/${config.repo}/`;
let website = `https://${owner}.github.io/${repo}/`;
if (config["status-website"] && config["status-website"].cname)
website = `https://${config["status-website"].cname}`;

Expand All @@ -136,7 +135,7 @@ ${pageStatuses
line.includes("[![Summary CI](https://github.com") &&
readmeContent.includes("<!--start: description-->")
)
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}\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/${owner}/${repo}/issues) as incident reports, [Actions](https://github.com/${owner}/${repo}/actions) as uptime monitors, and [Pages](${website}) for the status page.`;
return line;
})
.filter((line) => !line.startsWith("## [📈 Live Status]"))
Expand All @@ -154,14 +153,14 @@ ${pageStatuses
if (readmeContent.includes("<!--start: logo-->"))
readmeContent = `${logoStartText}${logoEndText}`;

let name = `[${config.owner}](${website})`;
let name = `[${owner}](${website})`;
if (
readmeContent.includes("[MIT](./LICENSE) © [Koj](https://koj.co)") ||
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: owner });
name = `[${org.data.name || owner}](${org.data.blog || website})`;
} catch (error) {}

// Remove Koj description
Expand All @@ -180,7 +179,7 @@ ${pageStatuses
// Change badges
readmeContent = readmeContent.replace(
new RegExp("upptime/upptime/workflows", "g"),
`${config.owner}/${config.repo}/workflows`
`${owner}/${repo}/workflows`
);

// Add repo description, topics, etc.
Expand Down
4 changes: 1 addition & 3 deletions src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import { generateSummary } from "./summary";

export const update = async (shouldCommit = false) => {
const config = safeLoad(await readFile(join(".", ".upptimerc.yml"), "utf8")) as UpptimeConfig;
const owner = config.owner;
const repo = config.repo;
const [owner, repo] = (process.env.GITHUB_REPOSITORY || "").split("/");

const octokit = new Octokit({
auth: config.PAT || process.env.GH_PAT || process.env.GITHUB_TOKEN,
userAgent: config["user-agent"] || process.env.USER_AGENT || "KojBot",
});
console.log("[debug] github object", JSON.stringify(process.env));

let hasDelta = false;
for await (const site of config.sites) {
Expand Down

0 comments on commit eeecfef

Please sign in to comment.