-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71c362e
commit 57e8cbc
Showing
11 changed files
with
249 additions
and
386 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,60 +1,52 @@ | ||
const { link, dateFmt } = require('./util') | ||
|
||
module.exports = (gh) => { | ||
return { | ||
...gh, | ||
authors: ghAuthors(gh), | ||
...format(gh), | ||
} | ||
} | ||
const { owner, repo } = gh.repository | ||
|
||
const format = (gh) => { | ||
const base = `https://github.com/${gh.repository.owner}/${gh.repository.repo}` | ||
const url = (...p) => `${base}/${p.join('/')}` | ||
const compare = (prev, current) => url('compare', prev, '...', current) | ||
return { | ||
pull: (number) => url('pull', number), | ||
compare: compare, | ||
commit: (sha) => url('commit', sha), | ||
release: (tag) => url('releases', 'tag', tag), | ||
title: (version, currentTag, previousTag) => | ||
`## ${link(version, previousTag && compare(previousTag, currentTag))} (${dateFmt()})`, | ||
tag: (component, version) => [component, `v${version.toString()}`].filter(Boolean).join('-'), | ||
} | ||
} | ||
const authors = async (commits) => { | ||
const response = {} | ||
|
||
const ghAuthors = (gh) => async (commits) => { | ||
const response = {} | ||
const shas = commits.map(c => c.sha).filter(Boolean) | ||
|
||
if (!commits.length) { | ||
return response | ||
} | ||
if (!shas.length) { | ||
return response | ||
} | ||
|
||
const { repository } = await gh.graphql( | ||
`fragment CommitAuthors on GitObject { | ||
... on Commit { | ||
authors (first:10) { | ||
nodes { | ||
user { login } | ||
name | ||
const { repository } = await gh.graphql( | ||
`fragment CommitAuthors on GitObject { | ||
... on Commit { | ||
authors (first:10) { | ||
nodes { | ||
user { login } | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
query { | ||
repository (owner:"${gh.repository.owner}", name:"${gh.repository.repo}") { | ||
${commits.map(({ sha: s }) => { | ||
return `_${s}: object (expression: "${s}") { ...CommitAuthors }` | ||
})} | ||
query { | ||
repository (owner:"${owner}", name:"${repo}") { | ||
${shas.map((s) => { | ||
return `_${s}: object (expression: "${s}") { ...CommitAuthors }` | ||
})} | ||
} | ||
}` | ||
) | ||
|
||
for (const [key, commit] of Object.entries(repository)) { | ||
if (commit) { | ||
response[key.slice(1)] = commit.authors.nodes | ||
.map((a) => a.user && a.user.login ? `@${a.user.login}` : a.name) | ||
.filter(Boolean) | ||
} | ||
}` | ||
) | ||
} | ||
|
||
for (const [sha, commit] of Object.entries(repository)) { | ||
response[sha.slice(1)] = commit.authors.nodes | ||
.map((a) => a.user && a.user.login ? `@${a.user.login}` : a.name) | ||
.filter(Boolean) | ||
return response | ||
} | ||
|
||
return response | ||
const url = (...p) => `https://github.com/${owner}/${repo}/${p.join('/')}` | ||
|
||
return { | ||
authors, | ||
pull: (number) => url('pull', number), | ||
commit: (sha) => url('commit', sha), | ||
compare: (a, b) => a ? url('compare', `${a.toString()}...${b.toString()}`) : null, | ||
} | ||
} |
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.