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

Support empty body and only remove existing labels #62

Merged
merged 6 commits into from
Mar 26, 2023

Conversation

dokimiki
Copy link
Contributor

@dokimiki dokimiki commented Mar 8, 2023

In #34 it was improved to check if body is undefined, but in #57 it was changed to check if it is falsy.

https://docs.github.com/ja/webhooks-and-events/webhooks/webhook-events-and-payloads#issues
https://docs.github.com/ja/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request

It says if the body of an Issue is empty, it returns null, so when getting it, null is replaced with an empty character.

translate by deepl.com

Fixes #61

@dokimiki
Copy link
Contributor Author

@stephanmiehe Is it possible to be reviewed or get an advice about this please?

@iba-1
Copy link

iba-1 commented Mar 20, 2023

@dokimiki I just tried it on a private repo, some more code is actually needed as:

issue-labeler/src/main.ts

Lines 119 to 125 in 1fff18e

function getIssueOrPRBody() {
const { issue, pull_request } = context.payload;
if (issue?.body === null || pull_request?.body === null) {
return '';
}
return issue?.body ?? pull_request?.body;
}

will return '' for an empty body, but '' is a falsy value and it'll be evaluated as false in this condition:

if (!issue_body) {
console.log("Could not get issue or PR body from context, exiting");
return;
}

therefore vanishing your intent of catching an empty body.

This could solve this problem, although is not very elegant:

 if (!issue_body && issue_body !== '' ) { 
   console.log("Could not get issue or PR body from context, exiting"); 
   return; 
 } 

@dokimiki
Copy link
Contributor Author

dokimiki commented Mar 20, 2023

@iba-1 thanks for testing my PR and founding bug!

To solve this problem, I have changed the method of evaluation, referring to your code, as follows:

const issue_body = getIssueOrPRBody();
if (issue_body === undefined) {
console.log("Could not get issue or PR body from context, exiting");
return;
}

translate by deepl.com

@stephanmiehe stephanmiehe changed the title Replace null issue body to empty character Support empty body and only remove existing labels Mar 26, 2023
@stephanmiehe stephanmiehe merged commit e24a3eb into github:master Mar 26, 2023
@dokimiki dokimiki deleted the allow-null-issue branch March 26, 2023 20:33
@iba-1
Copy link

iba-1 commented Mar 30, 2023

Thank you @stephanmiehe!

kodiakhq bot pushed a commit to X-oss-byte/Canary-nextjs that referenced this pull request Oct 10, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github/issue-labeler](https://togithub.com/github/issue-labeler) | action | major | `v2.6` -> `v3.2` |

---

### ⚠ Dependency Lookup Warnings ⚠

Warnings were logged while processing this repo. Please check the Dependency Dashboard for more information.

---

### Release Notes

<details>
<summary>github/issue-labeler (github/issue-labeler)</summary>

### [`v3.2`](https://togithub.com/github/issue-labeler/releases/tag/v3.2)

[Compare Source](https://togithub.com/github/issue-labeler/compare/v3.1...v3.2)

#### What's Changed

-   fix: read default token by [@&#8203;EndBug](https://togithub.com/EndBug) in [github/issue-labeler#67
-   feat: allow the use of custom issue numbers by [@&#8203;EndBug](https://togithub.com/EndBug) in [github/issue-labeler#66
-   fix: Use the correct input name so the default applies by [@&#8203;phated](https://togithub.com/phated) in [github/issue-labeler#72
-   feat: Add outputs of the labels added and removed by [@&#8203;phated](https://togithub.com/phated) in [github/issue-labeler#71
-   docs: GITHUB_TOKEN passing is required by [@&#8203;rajbos](https://togithub.com/rajbos) in [github/issue-labeler#75
-   feat: add option to include/exclude body as regex target by [@&#8203;amerikan](https://togithub.com/amerikan) in [github/issue-labeler#70

#### New Contributors

-   [@&#8203;EndBug](https://togithub.com/EndBug) made their first contribution in [github/issue-labeler#67
-   [@&#8203;phated](https://togithub.com/phated) made their first contribution in [github/issue-labeler#72
-   [@&#8203;rajbos](https://togithub.com/rajbos) made their first contribution in [github/issue-labeler#75
-   [@&#8203;amerikan](https://togithub.com/amerikan) made their first contribution in [github/issue-labeler#70

**Full Changelog**: github/issue-labeler@v3.1...v3.2

### [`v3.1`](https://togithub.com/github/issue-labeler/releases/tag/v3.1)

[Compare Source](https://togithub.com/github/issue-labeler/compare/v3.0...v3.1)

#### What's Changed

-   Support empty body and only remove existing labels by [@&#8203;dokimiki](https://togithub.com/dokimiki) in [github/issue-labeler#62

#### New Contributors

-   [@&#8203;dokimiki](https://togithub.com/dokimiki) made their first contribution in [github/issue-labeler#62

**Full Changelog**: github/issue-labeler@v3.0...v3.1

### [`v3.0`](https://togithub.com/github/issue-labeler/releases/tag/v3.0)

[Compare Source](https://togithub.com/github/issue-labeler/compare/v2.6...v3.0)

#### What's Changed

Breaking change: Issue labels that do not match a regex will no longer be removed by default unless you set `sync-labels:` to 1

-   feat: add sync-labels option by [@&#8203;balazsorban44](https://togithub.com/balazsorban44) in [github/issue-labeler#59

**Full Changelog**: github/issue-labeler@v2.6...v3.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/X-oss-byte/Canary-nextjs).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Labeler fails when issue body is empty
3 participants