Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ See [`action.yml`](action.yml) for full defaults.
| `responseRequiredLabel` | Label indicating a response is needed. | `more-information-needed` |
| `responseRequiredColor` | Hex color for the response label. | `ffffff` |
| `optionalFollowUpLabel` | Label to add after the author responds. | `undefined` |
| `optionalFollowUpLabelColor` | Hex color for the follow-up label. | `ffffff` |
| `optionalFollowUpColor` | Hex color for the follow-up label. | `ffffff` |
| `maxIssuesPerRun` | Maximum number of issues to close per scheduled run. | `50` |
| `closeComment` | Optional comment on close. Set to `false` to disable. | (Standard message)[^default-comment] |

Expand Down
15 changes: 13 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ inputs:
responseRequiredLabel:
description: Label indicating that a response from the original author is required
default: more-information-needed
optionalFollowUpColor:
description: Color for the `optionalFollowUpLabel`
optionalFollowUpLabel:
description: Label that will be added after the required label will be removed
optionalFollowUpLabelColor:
description: Color for the `optionalFollowUpLabel`
default: ffffff
description: 'Compatibility: Color for the `optionalFollowUpLabel`'
maxIssuesPerRun:
description: Number of Issues to close per workflow run
default: 50
Expand Down Expand Up @@ -77,6 +78,16 @@ runs:
id: run-action
shell: bash
working-directory: ${{ github.action_path }}
env:
INPUT_TOKEN: ${{ inputs.token }}
INPUT_CLOSECOMMENT: ${{ inputs.closeComment }}
INPUT_DAYSUNTILCLOSE: ${{ inputs.daysUntilClose }}
INPUT_RESPONSEREQUIREDCOLOR: ${{ inputs.responseRequiredColor }}
INPUT_RESPONSEREQUIREDLABEL: ${{ inputs.responseRequiredLabel }}
INPUT_OPTIONALFOLLOWUPCOLOR: ${{ inputs.optionalFollowUpColor }}
INPUT_OPTIONALFOLLOWUPLABEL: ${{ inputs.optionalFollowUpLabel }}
INPUT_OPTIONALFOLLOWUPLABELCOLOR: ${{ inputs.optionalFollowUpLabelColor }}
INPUT_MAXISSUESPERRUN: ${{ inputs.maxIssuesPerRun }}
run: ./bin/no-response-bin

- name: Handle Failure
Expand Down
9 changes: 6 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export default class Config {
/** An optional label to add when the `responseRequiredLabel` gets removed due to issue author's reply */
readonly optionalFollowUpLabel?: string

/** An optional label to add when the `responseRequiredLabel` gets removed due to issue author's reply */
readonly optionalFollowUpLabelColor?: string
/** Color to use when creating the label, encoded as a hex string. */
readonly optionalFollowUpColor?: string

readonly maxIssuesPerRun: number

Expand Down Expand Up @@ -81,7 +81,10 @@ export default class Config {

this.optionalFollowUpLabel = core.getInput('optionalFollowUpLabel') || undefined

this.optionalFollowUpLabelColor = core.getInput('optionalFollowUpLabelColor') || undefined
this.optionalFollowUpColor =
core.getInput('optionalFollowUpColor') ||
core.getInput('optionalFollowUpLabelColor') ||
'ffffff'
}

valueOrDefault(value: string, defaultValue: string): string {
Expand Down
26 changes: 17 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
// src/main.ts

import * as core from '@actions/core'
import * as github from '@actions/github'
import Config from './config'
import NoResponse from './no-response'

async function run(): Promise<void> {
try {
const eventName = process.env['GITHUB_EVENT_NAME']
core.debug(`Running action for event: ${eventName}`)
const eventName = github.context.eventName
const eventType =
'string' === typeof github.context.payload.action ? github.context.payload.action : undefined
core.info(`Running action for: name=${eventName} type=${eventType ?? ''}`)

const config = new Config()
const noResponse = new NoResponse(config)

if (eventName === 'schedule' || eventName === 'workflow_dispatch') {
if ('schedule' === eventName || 'workflow_dispatch' === eventName) {
await noResponse.sweep()
} else if (eventName === 'issue_comment') {
} else if ('issue_comment' === eventName) {
// React to comments on issues
// When it was the author, we must update the issue
await noResponse.handleAuthorCommented()
} else if (eventName === 'issues') {
if ('created' === eventType) {
await noResponse.handleAuthorCommented()
} else {
core.info(`Unrecognized issue_comment type: ${eventType}`)
}
} else if ('issues' === eventName) {
// React to issue events
// Specifically removing the optional label,
// after the issue was closed and removing the
// author from the assigned users
const action = process.env['GITHUB_EVENT_ACTION']

if ('labeled' === action) {
if ('labeled' === eventType) {
await noResponse.handleLabeled()
} else if ('closed' === action) {
} else if ('closed' === eventType) {
await noResponse.handleClosedIssue()
} else {
core.info(`Unrecognized issues type: ${eventType}`)
}
} else {
core.info(`This action was skipped. Unrecognized event: ${eventName}`)
Expand Down
11 changes: 6 additions & 5 deletions src/no-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class NoResponse {
this.optionalFollowUpLabel = {
name: this.config.optionalFollowUpLabel,
repo: this.repository,
color: this.config.optionalFollowUpLabelColor || 'ffffff'
color: this.config.optionalFollowUpColor || 'ffffff'
}
}
}
Expand Down Expand Up @@ -216,14 +216,15 @@ export default class NoResponse {
}

async handleClosedIssue(): Promise<void> {
if ('closed' !== github.context.payload.action) return
const payload = github.context.payload as IssuesEvent
if ('issues' !== github.context.eventName || 'closed' !== payload.action) return

const senderId = payload.sender?.id
if (!senderId || senderId !== payload.issue.user?.id) return

await this.initializeMetadata()
const payload = github.context.payload as IssuesEvent
const issueDetails = await this.issueCache.fetch(this.repository, payload.issue.number)

if (payload.issue.user.login !== payload.sender.login) return

await this.clearWorkflowLabels(issueDetails)
}

Expand Down