Skip to content

Commit

Permalink
Merge pull request #7 from Doist/luke/exclude-prs-in-draft-mode
Browse files Browse the repository at this point in the history
feat: Exclude PRs in Draft Mode
  • Loading branch information
lukemerrett authored Aug 23, 2024
2 parents 16ae579 + c0ef166 commit ba7b839
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Send Review Reminder Action

This action checks all opened pull requests review request.
This action checks all opened pull requests in a repository to find those that
are expecting a review they haven't received in the specified timeframe.

If a pull request has a pending review request and the specified review time
has passed, the action sends a reminder message on twist.com.
Any PRs found that have been waiting too long will have a reminder sent to a
Twist thread on their behalf.

## Usage:

Expand All @@ -24,12 +25,24 @@ jobs:
with:
message: '%reviewer%, please review [#%pr_number% - %pr_title%](%pr_url%)'
ignore_authors: 'tom, renovate'
exclude_draft_prs: true
review_time_ms: 86400000 # 1 day in milliseconds
twist_url: 'https://twist.com/api/v3/integration_incoming/post_data?install_id=[install id]&install_token=[install token]'
token: ${{ secrets.DOIST_BOT_TOKEN }}

```

### Parameters

|name|required?|example|description|
|----|---------|-------|-----------|
|review_time_ms|yes|`86400000`|The time in milliseconds a PR has to wait before a reminder will be sen, example is 24 hours|
|message|yes|`%reviewer%, `<br/>`please review `<br/>`[#%pr_number% - %pr_title%](%pr_url%)`|The reminder message to send, takes 4 parameters for string interpolation: `%reviewer%`, `%pr_number%`, `%pr_title%` and `%pr_url%`|
|twist_url|yes|`https://twist.com/api/v3/integration_incoming/`<br/>`post_data?`<br/>`install_id=[install id]`<br/>`&install_token=[install token]`|The installed integration url for posting a message to a Twist thread|
|token|yes|`adbc12431414`|The token for accessing the GitHub API to query the state of the PRs in a repo|
|ignore_authors|no|`tom, renovate`|Usernames of PR creators who's PRs will be ignored|
|exclude_draft_prs|no|`false`|Whether we should exclude draft PRs when checking reviews, defaults to false|

## Development

Uses Node v20.x
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ inputs:
token:
description: 'GitHub token'
required: true
exclude_draft_prs:
description: 'Whether we should exclude draft PRs when checking for pending reviews'
required: true
default: false
runs:
using: 'node20'
main: 'dist/index.js'
8 changes: 6 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9551,11 +9551,12 @@ const REVIEW_TIME_MS = parseInt(core.getInput('review_time_ms', { required: true
const IGNORE_AUTHORS = core.getInput('ignore_authors', { required: false });
const TWIST_URL = core.getInput('twist_url', { required: true });
const REMINDER_MESSAGE = core.getInput('message', { required: true });
const EXCLUDE_DRAFT_PRS = core.getBooleanInput('exclude_draft_prs', { required: true });
function run() {
return __awaiter(this, void 0, void 0, function* () {
const pullRequests = yield (0, pullrequest_1.fetchPullRequests)(GITHUB_TOKEN, GITHUB_REPO_OWNER, GITHUB_REPO);
for (const pullRequest of pullRequests) {
if ((0, pullrequest_1.shouldIgnore)(pullRequest, IGNORE_AUTHORS)) {
if ((0, pullrequest_1.shouldIgnore)(pullRequest, IGNORE_AUTHORS, EXCLUDE_DRAFT_PRS)) {
core.info(`Ignoring #${pullRequest.number} "${pullRequest.title}"`);
continue;
}
Expand Down Expand Up @@ -9648,14 +9649,17 @@ exports.fetchPullRequests = fetchPullRequests;
* A list of usernames, if the PR was created by any of these authors we will ignore it.
* @returns True if we should ignore the PR, otherwise false
*/
function shouldIgnore(pullRequest, ignoreAuthors) {
function shouldIgnore(pullRequest, ignoreAuthors, excludeDraftPRs) {
if (pullRequest.requested_reviewers.length === 0) {
return true;
}
const ignoreAuthorsArray = ignoreAuthors.split(',').map((author) => author.trim());
if (ignoreAuthorsArray.includes(pullRequest.user.login)) {
return true;
}
if (excludeDraftPRs && pullRequest.draft) {
return true;
}
return false;
}
exports.shouldIgnore = shouldIgnore;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ const REVIEW_TIME_MS = parseInt(core.getInput('review_time_ms', { required: true
const IGNORE_AUTHORS = core.getInput('ignore_authors', { required: false })
const TWIST_URL = core.getInput('twist_url', { required: true })
const REMINDER_MESSAGE = core.getInput('message', { required: true })
const EXCLUDE_DRAFT_PRS = core.getBooleanInput('exclude_draft_prs', { required: true })

async function run(): Promise<void> {
const pullRequests = await fetchPullRequests(GITHUB_TOKEN, GITHUB_REPO_OWNER, GITHUB_REPO)
for (const pullRequest of pullRequests) {
if (shouldIgnore(pullRequest, IGNORE_AUTHORS)) {
if (shouldIgnore(pullRequest, IGNORE_AUTHORS, EXCLUDE_DRAFT_PRS)) {
core.info(`Ignoring #${pullRequest.number} "${pullRequest.title}"`)
continue
}
Expand Down
10 changes: 9 additions & 1 deletion src/pullrequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export async function fetchPullRequests(
* A list of usernames, if the PR was created by any of these authors we will ignore it.
* @returns True if we should ignore the PR, otherwise false
*/
export function shouldIgnore(pullRequest: PullRequest, ignoreAuthors: string): boolean {
export function shouldIgnore(
pullRequest: PullRequest,
ignoreAuthors: string,
excludeDraftPRs: boolean,
): boolean {
if (pullRequest.requested_reviewers.length === 0) {
return true
}
Expand All @@ -44,6 +48,10 @@ export function shouldIgnore(pullRequest: PullRequest, ignoreAuthors: string): b
return true
}

if (excludeDraftPRs && pullRequest.draft) {
return true
}

return false
}

Expand Down
2 changes: 2 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type PullRequest = {
html_url: string
/** A list of users who a review has been requested from */
requested_reviewers: User[]
/** Whether the PR is currently in draft mode */
draft?: boolean
}

/** Result expected from our GraphQL request to GitHub for PR details */
Expand Down

0 comments on commit ba7b839

Please sign in to comment.