Skip to content

Commit 9386278

Browse files
committed
clean up create tag code
- Makes sure config is checked first before releases are fetched
1 parent af16e2a commit 9386278

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/pull/merged.js

+20-19
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,28 @@ module.exports.createTag = () => async context => {
3131
// Only create tags on "master"
3232
if (thread.base.ref !== context.payload.repository.default_branch) return
3333

34-
const { data } = await context.github.repos.listTags(context.repo({ per_page: 1 }))
34+
const isMajor = thread.labels.find(({ name }) => name.toLowerCase().includes('major'))
35+
const isMinor = thread.labels.find(({ name }) => name.toLowerCase().includes('minor'))
36+
const isPatch = thread.labels.find(({ name }) => name.toLowerCase().includes('patch'))
3537

36-
if (!(data && data[0] && data[0].name)) return
38+
if (!(isMajor || isMinor || isPatch)) {
39+
const config = await getConfig(context)
40+
const isAutoPatch =
41+
Array.isArray(config.merges) &&
42+
config.merges.find(c => {
43+
const value = c.action || c
44+
return typeof value === 'string' && value.trim().toLowerCase() === TAG
45+
})
3746

38-
const lastTag = data[0].name
47+
if (!isAutoPatch) return
48+
}
3949

40-
const match = /(v{0,1})(\d+)\.(\d+)\.(\d+)/.exec(lastTag)
50+
const { data } = await context.github.repos.listTags(context.repo({ per_page: 1 }))
51+
52+
const previousTag = data && data[0] && data[0].name
53+
if (!previousTag) return
54+
55+
const match = /(v{0,1})(\d+)\.(\d+)\.(\d+)/.exec(previousTag)
4156

4257
if (!match) return
4358

@@ -48,27 +63,13 @@ module.exports.createTag = () => async context => {
4863
patch: Number(match[4])
4964
}
5065

51-
const config = await getConfig(context)
52-
53-
const isMajor = thread.labels.find(({ name }) => name.toLowerCase().includes('major'))
54-
const isMinor = thread.labels.find(({ name }) => name.toLowerCase().includes('minor'))
55-
const isPatch = thread.labels.find(({ name }) => name.toLowerCase().includes('patch'))
56-
const isAutoPatch =
57-
Array.isArray(config.merges) &&
58-
config.merges.find(c => {
59-
const value = c.action || c
60-
return typeof value === 'string' && value.trim().toLowerCase() === TAG
61-
})
62-
6366
let tag
6467
if (isMajor) {
6568
tag = `${v.v}${v.major + 1}.0.0`
6669
} else if (isMinor) {
6770
tag = `${v.v}${v.major}.${v.minor + 1}.0`
68-
} else if (isPatch || isAutoPatch) {
69-
tag = `${v.v}${v.major}.${v.minor}.${v.patch + 1}`
7071
} else {
71-
return
72+
tag = `${v.v}${v.major}.${v.minor}.${v.patch + 1}`
7273
}
7374

7475
const sha = thread.merge_commit_sha

0 commit comments

Comments
 (0)