Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
Fix title update (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmisur authored Jul 13, 2021
1 parent ba0a04a commit 2a7bdec
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
'⚠️ danger ⚠️': '.github/labeler.yml'
'my-test-label': '.github/labeler.yml'
'my-test-label': '.github/labeler.yml'
17 changes: 13 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,23 @@ function addLabels(client, prNumber, labels) {
}
function updateTitle(client, prNumber, labels, title) {
return __awaiter(this, void 0, void 0, function* () {
const updated = title.endsWith(']')
? title.slice(0, title.lastIndexOf('[')) + ' [' + labels.join(' | ') + ']'
: title + ' [' + labels.join(' | ') + ']';
let updatedTitle = title;
if (labels.length > 0) {
if (title.endsWith(']')) {
updatedTitle = title.slice(0, title.lastIndexOf(' [')) + ' [' + labels.join(' | ') + ']';
}
else {
updatedTitle = title + ' [' + labels.join(' | ') + ']';
}
}
if (labels.length === 0 && title.endsWith(']')) {
updatedTitle = title.slice(0, title.lastIndexOf(' ['));
}
yield client.rest.pulls.update({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: prNumber,
title: updated
title: updatedTitle
});
});
}
Expand Down
18 changes: 14 additions & 4 deletions src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,24 @@ async function updateTitle(
labels: string[],
title: string
) {
const updated = title.endsWith(']')
? title.slice(0, title.lastIndexOf('[')) + ' [' + labels.join(' | ') + ']'
: title + ' [' + labels.join(' | ') + ']';
let updatedTitle = title;
if (labels.length > 0) {
if (title.endsWith(']')){
updatedTitle = title.slice(0, title.lastIndexOf(' [')) + ' [' + labels.join(' | ') + ']';
} else {
updatedTitle = title + ' [' + labels.join(' | ') + ']';
}
}

if (labels.length === 0 && title.endsWith(']')) {
updatedTitle = title.slice(0, title.lastIndexOf(' ['));
}

await client.rest.pulls.update({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: prNumber,
title: updated
title: updatedTitle
});
}

Expand Down

0 comments on commit 2a7bdec

Please sign in to comment.