Skip to content

Commit

Permalink
feat(notifier): watch major/minor/patch releases #53 #20
Browse files Browse the repository at this point in the history
  • Loading branch information
vfeskov committed Nov 1, 2018
1 parent 4b38690 commit a9f06ce
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion notifier/src/parts/sendEmailAndUpdateDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,32 @@ export default function sendEmailAndUpdateDb (users: ActionableUser[], collectio
}))
}

const MAJOR = /^v?\d+\.0\.0$/
const MINOR = /^v?\d+\.\d+\.0$/
const PATCH = /^v?\d+\.\d+\.\d+$/
export async function sendEmail (user: ActionableUser): Promise<any> {
const { email, mutedRepos = [], actionableRepos } = user
const { email, mutedRepos = [], majors = [], minors = [], patches = [], actionableRepos } = user
const repos = actionableRepos[SEND_EMAIL_AND_UPDATE_ALERTED]
.filter(({ repo }) => !mutedRepos.includes(repo))
.map(({ repo, tags }) => {
if (majors.includes(repo)) {
tags = filteredTags(tags, MAJOR)
} else if (minors.includes(repo)) {
tags = filteredTags(tags, MINOR)
} else if (patches.includes(repo)) {
tags = filteredTags(tags, PATCH)
}
return { repo, tags }
})
.filter(({ tags }) => tags.length)
if (!repos.length) { return }
return new Email(email, repos).send()
}

function filteredTags (tags, pattern) {
return tags.filter(({ name }) => pattern.test(name))
}

export async function updateDb (user: ActionableUser, collection: Collection): Promise<any> {
const { _id, email, alerted, actionableRepos } = user
const $set: any = {}
Expand Down

0 comments on commit a9f06ce

Please sign in to comment.