-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Display recent commits * - Support more repositories - Fix font size and alignment - Sort by date - Use GH Api token * Supply repositories via .env file; Add time to list of commits; Skip commits page if there are no repositories configured * Update CommITCrowd banner; Fix next flow for commits page. Fix feedback --------- Co-authored-by: Tobias de Bruijn <[email protected]>
- Loading branch information
1 parent
92a39b7
commit 281997c
Showing
9 changed files
with
1,988 additions
and
1,840 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.png" /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.