Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add github no reply email detection #88

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 91 additions & 75 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
export const CONFIRMATION_MESSAGE = 'All good 🎉 feels good to give back!'
export const CONFIRMATION_COMMENT = `Thank you for your contribution to WebdriverIO! Your pull request has been marked as an "Expensable" contribution. We've sent you an email with further instructions on how to claim your expenses from our development fund. Please make sure to check your spam folder as well. If you have any questions, feel free to reach out to us at [email protected]__ or in the contributing channel on [Discord](https://discord.webdriver.io).

We are looking forward to more contributions from you in the future 🙌
const COMMENT_HEADER = `Thank you for your contribution to WebdriverIO! Your pull request has been marked as an "Expensable" contribution.

We've sent you an email with further instructions on how to claim your expenses from our development fund.\n`

const EMAIL_WARNING = `Please make sure to check your spam folder as well. If you have any questions, feel free to reach out to us at [email protected]__ or in the contributing channel on [Discord](https://discord.webdriver.io).\n\n`
const EMAIL_WARNING_GHNOREPLY = `⚠️ You seemed to have committed using an email address ending up with \`@users.noreply.github.com\`, if you don't receive the email please feel free to reach out to us at [email protected]__ or in the contributing channel on [Discord](https://discord.webdriver.io).\n\n`

const COMMENT_FOOTER = `We are looking forward to more contributions from you in the future 🙌

Have a nice day,
The WebdriverIO Team 🤖`

export const CONFIRMATION_COMMENT =
COMMENT_HEADER + EMAIL_WARNING + COMMENT_FOOTER

export const CONFIRMATION_COMMENT_GHNOREPLY =
COMMENT_HEADER + EMAIL_WARNING_GHNOREPLY + COMMENT_FOOTER

export const FROM = 'WebdriverIO Team <[email protected]>'
export const BCC = '[email protected]'
18 changes: 16 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Octokit } from '@octokit/rest'
import Email from './mail.js'
import {
CONFIRMATION_COMMENT,
CONFIRMATION_COMMENT_GHNOREPLY,
CONFIRMATION_MESSAGE,
FROM as from,
BCC as bcc
Expand Down Expand Up @@ -103,7 +104,16 @@ export async function expense(
const prAuthors = new Set(
commits.data.map(commit => commit.commit.author?.email).filter(Boolean)
)
const prAuthorEmail = prAuthors.values().next().value
const prAuthorEmail = prAuthors.values().next().value as string

/**
* Checks if the email address ends up with the Github no reply.
* There is an issue with GitHub not redirecting emails to the user
* See issue #86 for more information
*/
const isNoReplyGithubEmail = prAuthorEmail.endsWith(
'@users.noreply.github.com'
)

console.log(`Send expense email to ${prAuthorEmail} for PR #${prNumber}`)
console.log(`Amount to be expensed: $${expenseAmount}`)
Expand Down Expand Up @@ -137,13 +147,17 @@ export async function expense(
issue_number: prNumber
} as const

const comment = isNoReplyGithubEmail
? CONFIRMATION_COMMENT_GHNOREPLY
: CONFIRMATION_COMMENT

/**
* Add a comment to the PR that an expense email has been sent out
*/
console.log(`Adding comment to PR #${prNumber}, letting user know...`)
await api.issues.createComment({
...issueOptions,
body: `Hey __${pr.data.user.login}__ 👋\n\n${CONFIRMATION_COMMENT}`
body: `Hey __${pr.data.user.login}__ 👋\n\n${comment}`
})

console.log(`Adding expense label to PR #${prNumber}...`)
Expand Down
Loading