Skip to content

Commit

Permalink
Fix bug to produce same outputs when unnecessary to update label (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
micnncim authored May 3, 2020
1 parent 3abae93 commit 4d4eb59
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ Must be a maximal number, rather than a range.

## Outputs

| Name | Type | Description |
| -------------- | ------ | ---------------------------------------------------------------------------------------------------- |
| `new_label` | string | The new label's name to be added. |
| `stale_labels` | string | The stale labels' name to be removed. If there're multiple labels, they're separated by line breaks. |
| Name | Type | Description |
| -------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `new_label` | string | The new label's name to be added. If there's no label to be added, it the value is `''`. |
| `stale_labels` | string | The stale labels' name to be removed. If there're multiple labels, they're separated by line breaks. If there's no labels to be removed, it the value is `''`. |

## Example

Expand Down
10 changes: 6 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5055,12 +5055,14 @@ class Processor {
}
process() {
const changes = Processor.getChangedLines();
const newLabel = this.determineLabel(changes);
const desiredLabel = this.determineLabel(changes);
const currentLabels = this.getCurrentLabels();
const newLabel = currentLabels.includes(desiredLabel) ? '' : desiredLabel;
const staleLabel = currentLabels.filter(label => label !== desiredLabel);
core.setOutput('new_label', newLabel);
const staleLabels = this.getCurrentSizeLabels();
core.setOutput('stale_labels', staleLabels.join('\n'));
core.setOutput('stale_labels', staleLabel.join('\n'));
}
getCurrentSizeLabels() {
getCurrentLabels() {
const payload = github.context
.payload;
return payload.pull_request.labels
Expand Down
13 changes: 8 additions & 5 deletions src/Processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ export class Processor {
process() {
const changes = Processor.getChangedLines();

const newLabel = this.determineLabel(changes);
core.setOutput('new_label', newLabel);
const desiredLabel = this.determineLabel(changes);
const currentLabels = this.getCurrentLabels();

const newLabel = currentLabels.includes(desiredLabel) ? '' : desiredLabel;
const staleLabel = currentLabels.filter(label => label !== desiredLabel);

const staleLabels = this.getCurrentSizeLabels();
core.setOutput('stale_labels', staleLabels.join('\n'));
core.setOutput('new_label', newLabel);
core.setOutput('stale_labels', staleLabel.join('\n'));
}

private getCurrentSizeLabels(): string[] {
private getCurrentLabels(): string[] {
const payload = github.context
.payload as Webhooks.WebhookPayloadPullRequest;

Expand Down

0 comments on commit 4d4eb59

Please sign in to comment.