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 option to include/exclude body as regex target #70

Merged
merged 2 commits into from
Jul 4, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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/issue-labeler@v3.2 #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