mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Add commit dates to apps
This commit is contained in:
parent
08fc82abfd
commit
25f5343b25
2 changed files with 97 additions and 2 deletions
|
|
@ -2,6 +2,9 @@
|
||||||
import { promises as fs } from 'fs'
|
import { promises as fs } from 'fs'
|
||||||
import MarkdownIt from 'markdown-it'
|
import MarkdownIt from 'markdown-it'
|
||||||
import slugify from 'slugify'
|
import slugify from 'slugify'
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
import parseGithubDate from './parse-github-date'
|
||||||
|
|
||||||
|
|
||||||
const md = new MarkdownIt()
|
const md = new MarkdownIt()
|
||||||
|
|
@ -14,6 +17,7 @@ export const statuses = {
|
||||||
'🚫': 'no'
|
'🚫': 'no'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const getTokenLinks = function ( childTokens ) {
|
const getTokenLinks = function ( childTokens ) {
|
||||||
|
|
||||||
const tokenList = []
|
const tokenList = []
|
||||||
|
|
@ -53,12 +57,60 @@ const getTokenLinks = function ( childTokens ) {
|
||||||
return tokenList
|
return tokenList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const lookForLastUpdated = function (app, commits) {
|
||||||
|
|
||||||
|
for (const { node: commit } of commits) {
|
||||||
|
|
||||||
|
// console.log('commit', commit)
|
||||||
|
|
||||||
|
// $$ If message body contains endpoint
|
||||||
|
if (commit.messageBody.includes(app.endpoint)) {
|
||||||
|
// console.log('Found', app.name ,commit.committedDate)
|
||||||
|
return commit.committedDate
|
||||||
|
}
|
||||||
|
|
||||||
|
// $$ If message body contains App Name
|
||||||
|
if (commit.messageBody.includes(app.name)) {
|
||||||
|
// console.log('Found', app.name ,commit.committedDate)
|
||||||
|
return commit.committedDate
|
||||||
|
}
|
||||||
|
|
||||||
|
// $$ If message headline contains App Name
|
||||||
|
if (commit.messageHeadline.includes(app.name)) {
|
||||||
|
// console.log('Found', app.name ,commit.committedDate)
|
||||||
|
return commit.committedDate
|
||||||
|
}
|
||||||
|
|
||||||
|
// $$$ If commits comments contains endpoint
|
||||||
|
for (const { node: comment } of commit.comments.edges) {
|
||||||
|
if (comment.body.includes(app.endpoint)) {
|
||||||
|
// console.log('Found', app.name ,commit.committedDate)
|
||||||
|
return commit.committedDate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export default async function () {
|
export default async function () {
|
||||||
|
|
||||||
const readmeContent = await fs.readFile('./README-temp.md', 'utf8')
|
const readmeContent = await fs.readFile('./README-temp.md', 'utf8')
|
||||||
|
|
||||||
// console.log('readmeContent', readmeContent)
|
// console.log('readmeContent', readmeContent)
|
||||||
|
|
||||||
|
// Fetch Commits
|
||||||
|
const response = await axios.get(process.env.COMMITS_SOURCE)
|
||||||
|
// Extract commit from response data
|
||||||
|
const commits = response.data.data.viewer.repository.defaultBranchRef.target.history.edges
|
||||||
|
// console.log('commits', commits)
|
||||||
|
|
||||||
|
// Save commits to file just in case
|
||||||
|
await fs.writeFile('./commits-data.json', JSON.stringify(commits))
|
||||||
|
|
||||||
|
|
||||||
// Parse markdown
|
// Parse markdown
|
||||||
const result = md.parse(readmeContent)
|
const result = md.parse(readmeContent)
|
||||||
|
|
||||||
|
|
@ -119,6 +171,8 @@ export default async function () {
|
||||||
strict: true
|
strict: true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const endpoint = `/app/${appSlug}`
|
||||||
|
|
||||||
let status = 'unknown'
|
let status = 'unknown'
|
||||||
|
|
||||||
for (const statusKey in statuses) {
|
for (const statusKey in statuses) {
|
||||||
|
|
@ -128,14 +182,22 @@ export default async function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lastUpdatedRaw = lookForLastUpdated({ name, endpoint }, commits)
|
||||||
|
|
||||||
|
const lastUpdated = (lastUpdatedRaw) ? {
|
||||||
|
raw: lastUpdatedRaw,
|
||||||
|
timestamp: parseGithubDate(lastUpdatedRaw).timestamp,
|
||||||
|
} : null
|
||||||
|
|
||||||
|
|
||||||
appList.push({
|
appList.push({
|
||||||
name,
|
name,
|
||||||
status,
|
status,
|
||||||
|
lastUpdated,
|
||||||
url,
|
url,
|
||||||
text,
|
text,
|
||||||
slug: appSlug,
|
slug: appSlug,
|
||||||
endpoint: `/app/${appSlug}`,
|
endpoint,
|
||||||
section: {
|
section: {
|
||||||
label: sectionTitle,
|
label: sectionTitle,
|
||||||
slug: sectionSlug
|
slug: sectionSlug
|
||||||
|
|
|
||||||
33
helpers/parse-github-date.js
Normal file
33
helpers/parse-github-date.js
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
// in miliseconds
|
||||||
|
const units = {
|
||||||
|
year : 24 * 60 * 60 * 1000 * 365,
|
||||||
|
month : 24 * 60 * 60 * 1000 * 365/12,
|
||||||
|
day : 24 * 60 * 60 * 1000,
|
||||||
|
hour : 60 * 60 * 1000,
|
||||||
|
minute: 60 * 1000,
|
||||||
|
second: 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' })
|
||||||
|
|
||||||
|
const getRelativeTime = function (d1, d2 = new Date()) {
|
||||||
|
var elapsed = d1 - d2
|
||||||
|
|
||||||
|
// "Math.abs" accounts for both "past" & "future" scenarios
|
||||||
|
for (var u in units)
|
||||||
|
if (Math.abs(elapsed) > units[u] || u == 'second')
|
||||||
|
return rtf.format(Math.round(elapsed/units[u]), u)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function (rawDate) {
|
||||||
|
|
||||||
|
const date = new Date(rawDate)
|
||||||
|
|
||||||
|
return {
|
||||||
|
date,
|
||||||
|
raw: rawDate,
|
||||||
|
timestamp: date.getTime(),
|
||||||
|
relative: getRelativeTime(date)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue