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

Add the possibility to configure the base URL of the GitHub API #52

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .upptimerc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ status-website:
cname: demo.upptime.js.org
logoUrl: https://github.com/raw/upptime/upptime.js.org/master/static/img/icon.svg
name: Upptime
apiBaseUrl: https://api.github.com
introTitle: "**Upptime** is the open-source uptime monitor and status page, powered entirely by GitHub."
introMessage: This is a sample status page which uses **real-time** data from our [Github repository](https://github.com/koj-co/upptime). No server required — just GitHub Actions, Issues, and Pages. [**Get your own for free**](https://github.com/koj-co/upptime)
navbar:
Expand Down
6 changes: 2 additions & 4 deletions src/components/ActiveIncidents.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<script>
import Loading from "../components/Loading.svelte";
import { Octokit } from "@octokit/rest";
import { onMount } from "svelte";
import config from "../data/config.json";
import { createOctokit } from "../utils/createOctokit";

let loading = true;
const octokit = new Octokit({
userAgent: config["user-agent"],
});
const octokit = createOctokit();
const owner = config.owner;
const repo = config.repo;
let incidents = [];
Expand Down
11 changes: 3 additions & 8 deletions src/components/Graph.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<script>
import Loading from "../components/Loading.svelte";
import { Octokit } from "@octokit/rest";
import { onMount } from "svelte";
import config from "../data/config.json";
import Line from "svelte-chartjs/src/Line.svelte";
import { createOctokit } from "../utils/createOctokit";

export let slug;
let loading = true;
const octokit = new Octokit({
userAgent: config["user-agent"],
});
const octokit = createOctokit();
const owner = config.owner;
const repo = config.repo;
let commits = [];
Expand All @@ -34,9 +32,7 @@
});
data = commits
.filter((commit) => commit.commit.message.includes("ms) [skip ci]"))
.map((commit) =>
parseInt(commit.commit.message.split(" in ")[1].split("ms")[0])
);
.map((commit) => parseInt(commit.commit.message.split(" in ")[1].split("ms")[0]));
labels = commits
.filter((commit) => commit.commit.message.includes("ms) [skip ci]"))
.map((commit) => new Date(commit.commit.committer.date).toLocaleString());
Expand All @@ -45,7 +41,6 @@
</script>

<style>

</style>

<section>
Expand Down
6 changes: 2 additions & 4 deletions src/components/History.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<script>
import Loading from "../components/Loading.svelte";
import { Octokit } from "@octokit/rest";
import { onMount } from "svelte";
import config from "../data/config.json";
import { createOctokit } from "../utils/createOctokit";

export let slug;
let loading = true;
const octokit = new Octokit({
userAgent: config["user-agent"],
});
const octokit = createOctokit();
const owner = config.owner;
const repo = config.repo;
let incidents = [];
Expand Down
6 changes: 2 additions & 4 deletions src/components/Incident.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<script>
import Loading from "../components/Loading.svelte";
import { Octokit } from "@octokit/rest";
import { onMount } from "svelte";
import snarkdown from "snarkdown";
import config from "../data/config.json";
import { createOctokit } from "../utils/createOctokit";

export let number;

let md = snarkdown;
let loading = true;
let loadingIncident = true;

const octokit = new Octokit({
userAgent: config["user-agent"],
});
const octokit = createOctokit();
const owner = config.owner;
const repo = config.repo;
let comments = [];
Expand Down
6 changes: 2 additions & 4 deletions src/components/Incidents.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<script>
import Loading from "../components/Loading.svelte";
import { Octokit } from "@octokit/rest";
import { onMount } from "svelte";
import config from "../data/config.json";
import { createOctokit } from "../utils/createOctokit";

let loading = true;
const octokit = new Octokit({
userAgent: config["user-agent"],
});
const octokit = createOctokit();
const owner = config.owner;
const repo = config.repo;
let incidents = [];
Expand Down
13 changes: 8 additions & 5 deletions src/components/LiveStatus.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<script>
import Loading from "../components/Loading.svelte";
import { Octokit } from "@octokit/rest";
import { onMount } from "svelte";
import config from "../data/config.json";
import { createOctokit } from "../utils/createOctokit";

let loading = true;
const octokit = new Octokit({
userAgent: config["user-agent"],
});
const octokit = createOctokit();
const owner = config.owner;
const repo = config.repo;
const { apiBaseUrl } = config["status-website"];
let sites = [];

const isGitHubApi = apiBaseUrl.includes("api.github.com");
const userContentBaseUrl = isGitHubApi ? `https://github.com/raw` : apiBaseUrl;
const graphsBaseUrl = `${userContentBaseUrl}/${owner}/${repo}/master/graphs`;

onMount(async () => {
sites = JSON.parse(
atob(
Expand Down Expand Up @@ -44,7 +47,7 @@
{#each sites as site}
<article
class={`${site.status} link`}
style={`background-image: url("https://github.com/raw/${owner}/${repo}/master/graphs/${site.slug}.png`}>
style={`background-image: url("${graphsBaseUrl}/${site.slug}.png`}>
<h4><a href={`history/${site.slug}`}>{site.name}</a></h4>
<div>
{@html config.i18n.overallUptime.replace(/\$UPTIME/g, site.uptime)}
Expand Down
7 changes: 2 additions & 5 deletions src/components/Summary.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<script>
import Loading from "../components/Loading.svelte";
import { Octokit } from "@octokit/rest";
import { onMount } from "svelte";
import config from "../data/config.json";
import { createOctokit } from "../utils/createOctokit";

export let slug;
let loading = true;
const octokit = new Octokit({
userAgent: config["user-agent"],
});
const octokit = createOctokit();
const owner = config.owner;
const repo = config.repo;
let summary = null;
Expand All @@ -30,7 +28,6 @@
</script>

<style>

</style>

<section>
Expand Down
11 changes: 11 additions & 0 deletions src/utils/createOctokit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Octokit } from "@octokit/rest";
import config from "../data/config.json";

const { apiBaseUrl: baseUrl } = config["status-website"]
const userAgent = config.userAgent;

export const createOctokit = () =>
new Octokit({
baseUrl,
userAgent,
});