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

Recent commits page #118

Merged
merged 6 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ VITE_ACTIVITY_ENDPOINT=https://koala.svsticky.nl/api/activities
# Timers
VITE_LOAD_INTERVAL=900000 # 15 * 60 * 1000
VITE_NEXT_INTERVAL=8000 # 8 * 1000

# Commits page
VITE_GITHUB_REPOS=svsticky/radio svsticky/constipated-koala svsticky/static-sticky
VITE_GITHUB_API_TOKEN=
TobiasDeBruijn marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 21 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ import BoardText from "./components/BoardText";
import Quotes from "./components/Quotes";
import Ad from "./components/Ad";
import { TeamPage } from "./components/Team";
import { LOGO } from "./helpers/env";
import {GITHUB_REPOS, LOGO} from "./helpers/env";
import { CommitsPage } from "./components/Commits";

export default class App extends Component {
constructor(props) {
super(props);

this.state = {
current: "activities",
current: "commits",
TobiasDeBruijn marked this conversation as resolved.
Show resolved Hide resolved
index: 0,
};
}

next() {
return;

TobiasDeBruijn marked this conversation as resolved.
Show resolved Hide resolved
const params = new URLSearchParams(window.location.search);

const display_internal = params.get("internal") == "true";
Expand Down Expand Up @@ -64,6 +67,20 @@ export default class App extends Component {
});
break;
case "team":

// Dont go to commits page if no repositories are configured
if(GITHUB_REPOS === "") {
this.setState({
current: "activities",
});
} else {
this.setState({
current: "commits",
});
}

break;
case "commits":
this.setState({
current: "activities",
});
Expand Down Expand Up @@ -113,6 +130,8 @@ export default class App extends Component {
return <Quotes />;
case "team":
return <TeamPage />;
case "commits":
return <CommitsPage />;
default:
return;
}
Expand Down
97 changes: 97 additions & 0 deletions src/components/Commits.jsx
TobiasDeBruijn marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {octokit} from "../helpers/github";
import {useQuery} from "../hooks/useQuery";
import Poster from "./Poster";
import {GITHUB_REPOS} from "../helpers/env.js";

function getCommits(owner, repo) {
return useQuery(async () => {
const res = await octokit.rest.repos.listCommits({
owner: owner,
repo: repo,
per_page: 4,
});

return res.data.map((commit, index) => {
return ({
index: index,
message: commit.commit.message,
author: commit.commit.author.name ?? commit.commit.author.login,
repo: repo,
date: new Date(commit.commit.committer.date),
owner: owner
})
});
});
}

function getAllCommits() {
const v = GITHUB_REPOS
.split(" ")
.map(fIdent => {
const v = fIdent.split("/");
return getCommits(v[0], v[1]);
});

let commits = v
.map(v => v.data)
.flat();
commits.sort((a, b) => {
return b?.date?.getTime() - a?.date?.getTime();
});

const isLoading = v.map(v => v.isLoading);

return {
data: commits.slice(0, 5),
isLoading: isLoading.includes(true),
}
}

function formatTime(date) {
let hh = date.getHours();
let mm = date.getMinutes();

if (hh < 10) hh = '0' + hh;
if (mm < 10) mm = '0' + mm;

return `${hh}:${mm}`
}

function formatDate(date) {
let dd = date.getDate();
let mm = date.getMonth() + 1;
const yyyy = date.getFullYear();

if (dd < 10) dd = '0' + dd;
if (mm < 10) mm = '0' + mm;

return `${dd}-${mm}-${yyyy}`;
}

export const CommitsPage = () => {
const { data: commits, isLoading } = getAllCommits();
if (isLoading) return <> Loading... </>;

return (
<div>
<h1 className="commits-title"> Recent commits</h1>
<ul className="commits-list">
{commits?.map((commit) => {
return (
<>
<li key={commit.index} className="commits-list__item">
<p className="commits-list__item__message">
{commit.message.split('\n')[0]}
</p>
<p className="commits-list__item__meta">
On <em>{commit.owner}/{commit.repo}</em> by <strong>{commit.author}</strong> ({formatDate(commit.date)} {formatTime(commit.date)})
</p>
</li>
</>
);
})}
</ul>
<Poster poster="/commitcrowd.jpeg" />
</div>
);
};
3 changes: 3 additions & 0 deletions src/helpers/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
export const CONTENTFUL_SPACE_ID = import.meta.env.VITE_CONTENTFUL_SPACE_ID;
export const CONTENTFUL_ACCESS_TOKEN = import.meta.env.VITE_CONTENTFUL_ACCESS_TOKEN;

export const GITHUB_API_TOKEN = import.meta.env.VITE_GITHUB_API_TOKEN;
export const GITHUB_REPOS = import.meta.env.VITE_GITHUB_REPOS;

export const KOALA_ACTIVITY_ENDPOINT = import.meta.env.VITE_ACTIVITY_ENDPOINT;
export const LOGO = import.meta.env.VITE_LOGO;
TobiasDeBruijn marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion src/helpers/github.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Octokit } from "octokit";
import { GITHUB_API_TOKEN } from './env.js'


export const octokit = new Octokit({ auth: "" });
export const octokit = new Octokit({ auth: GITHUB_API_TOKEN });
26 changes: 26 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ body {
position: fixed;
}

.commits-title,
.commits-list {
margin-left: 50px;
margin-top: 50px;
padding: 0;
color: #dae1e3;
max-height: 70%;
width: 50%;
}

.commits-list > li {
padding: 0;
}

.commits-list__item__message {
font-size: 35px;
padding: 0;
margin: 0;
}

.commits-list__item__meta {
font-size: 25px;
padding: 0;
margin: 1rem 1rem 1rem 2rem;
}

.full-advertisement,
.full-advertisement > .poster {
position: absolute;
Expand Down
Loading