-
Notifications
You must be signed in to change notification settings - Fork 2
/
check-for-emojis.js
40 lines (31 loc) · 1.05 KB
/
check-for-emojis.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
40
const gitmojis = require('./gitmojis').gitmojis
const hasGitmoji = ({ commit }) => gitmojis.some(gitmoji => commit.message.includes(gitmoji.emoji))
const mergeCommitRegex = /[Mm]erge/
function isMergeCommit({ commit }) {
return mergeCommitRegex.test(commit.message)
}
const allCommitsAreValid = commits =>
commits.every(commit => hasGitmoji(commit) || isMergeCommit(commit))
const checkForEmojis = async context => {
const { github, payload } = context
const repo = payload.repository.name
const owner = payload.repository.owner.login
const { sha } = payload.pull_request.head
const response = await github.pullRequests.getCommits({
owner,
repo,
number: payload.pull_request.number,
})
const [state, description] = allCommitsAreValid(response.data)
? ['success', 'The Gitmoji Police is satisfied with your commit messages.']
: ['failure', 'This PR is missing Gitmojis.']
github.repos.createStatus({
context: 'Gitmoji Police',
description,
owner,
repo,
state,
sha,
})
}
module.exports = checkForEmojis