Skip to content

Commit

Permalink
feat: add option to include/exclude body as regex target (#70)
Browse files Browse the repository at this point in the history
* feat: add option to include/exclude body as regex target

* build: create build
  • Loading branch information
amerikan authored Jul 4, 2023
1 parent c43637b commit e15315c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ on:
permissions:
issues: write
contents: read
jobs:
triage:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -79,7 +79,7 @@ on:
permissions:
issues: write
contents: read
jobs:
triage:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -125,7 +125,7 @@ on:
permissions:
issues: write
contents: read
jobs:
triage:
runs-on: ubuntu-latest
Expand All @@ -138,6 +138,31 @@ jobs:
repo-token: ${{ github.token }}
```

### Example of *only* including the issue title, but not the body in the regex target

Set `include-title: 1` and `include-body: 0`.

```yml
name: "Issue Labeler"
on:
issues:
types: [opened, edited]
permissions:
issues: write
contents: read
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: github/[email protected] #May not be the latest version
with:
configuration-path: .github/labeler.yml
include-title: 1
include-body: 0
```

### Syncing Labels

By default, labels that no longer match are not removed from the issue. To enable this functionality, explicity
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ inputs:
description: 'The name of the label that should be added to an issue where the specified `version-regex` can not be found.'
required: false
include-title:
description: 'Include the title in addition to the body in the regex target'
description: 'Include the title in the regex target'
required: false
default: "0"
include-body:
description: 'Include the body in the regex target'
required: false
default: "1"
sync-labels:
description: 'Remove the label from the issue if the label regex does not match'
required: false
Expand All @@ -33,6 +37,7 @@ inputs:
description: 'The number of the issue/PR to label'
required: false
default: ${{ github.event.issue.number || github.event.pull_request.number }}

outputs:
labels-added:
description: 'The labels that were added by the action, as a stringified array.'
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js

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 @@ -20,6 +20,7 @@ async function run() {
required: false,
});
const includeTitle = parseInt(getInput("include-title", { required: false }));
const includeBody = parseInt(getInput("include-body", { required: false }));
const syncLabels = parseInt(getInput("sync-labels", { required: false }));

const issue_number = parseInt(getInput("issue-number", { required: true }))
Expand Down Expand Up @@ -92,7 +93,7 @@ async function run() {

let issueContent = "";
if (includeTitle === 1) issueContent += `${issue_title}\n\n`;
issueContent += issue_body;
if (includeBody === 1) issueContent += issue_body;

for (const [label, globs] of labelRegexes.entries()) {
if (checkRegexes(issueContent, globs)) {
Expand Down

0 comments on commit e15315c

Please sign in to comment.