-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (38 loc) · 1.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const Git = require('./helpers/Git')
const logger = require('./helpers/logger')
const MarkdownGenerator = require('./generators/Markdown')
const versionEvaluator = require('./version/versionEvaluator')
module.exports = async({ token, repo, branch, prefix, keys, versionType, style }) => {
try {
const [owner, repoName] = repo.split('/')
const git = new Git({ owner, repo: repoName, branch, prefix, token })
const release = await git
.getLatestRelease()
if (release === null) {
logger.error('No previous release found!')
return
}
logger.print(`> Latest release found on GitHub: ${logger.highlight(release.name)}`)
logger.print(`Fetching commits since tag ${logger.bold(release.tag)}...`)
const tag = await git.getTagByName({ tag: release.tag })
const commits = await git
.getCommits({ until: tag.sha })
.then(commits => {
logger.print(`> ${logger.highlight(`${commits.length} commits`)} found since latest release`)
return commits
})
const version = await versionEvaluator.evaluate({
type: versionType,
oldTag: release.tag,
prefix: prefix,
git
})
const markdown = MarkdownGenerator.generate({
keys, owner, repo: repoName, oldTag: release.tag, newTag: version.tag, commits, style
})
await git.createRelease({ branch, name: version.name, tag: version.tag, markdown })
logger.success(`Release ${logger.bold(version.tag)} generated successfully.`)
} catch (error) {
logger.error(error)
}
}