This repository has been archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from seprintour/link-pr-to-issue
Assign PR owner to linked issue
- Loading branch information
Showing
6 changed files
with
126 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { getBotContext, getLogger } from "../../bindings"; | ||
import { addAssignees, getIssueByNumber, getPullRequests } from "../../helpers"; | ||
import { gitLinkedIssueParser } from "../../helpers/parser"; | ||
import { Payload } from "../../types"; | ||
|
||
// Check for pull requests linked to their respective issues but not assigned to them | ||
export const checkPullRequests = async () => { | ||
const context = getBotContext(); | ||
const logger = getLogger(); | ||
const pulls = await getPullRequests(context); | ||
|
||
if (pulls.length === 0) { | ||
logger.debug(`No pull requests found at this time`); | ||
return; | ||
} | ||
|
||
const payload = context.payload as Payload; | ||
|
||
// Loop through the pull requests and assign them to their respective issues if needed | ||
for (const pull of pulls) { | ||
let pullRequestLinked = await gitLinkedIssueParser({ | ||
owner: payload.repository.owner.login, | ||
repo: payload.repository.name, | ||
issue_number: pull.number, | ||
}); | ||
|
||
// if pullRequestLinked is empty, continue | ||
if (pullRequestLinked == "") { | ||
continue; | ||
} | ||
|
||
const linkedIssueNumber = pullRequestLinked.substring(pullRequestLinked.lastIndexOf("/") + 1); | ||
|
||
// Check if the pull request opener is assigned to the issue | ||
const opener = pull!.user!.login; | ||
|
||
let issue = await getIssueByNumber(context, +linkedIssueNumber); | ||
|
||
// if issue is already assigned, continue | ||
if (issue!.assignees!.length > 0) { | ||
logger.debug(`Issue already assigned, ignoring...`); | ||
continue; | ||
} | ||
|
||
const assignedUsernames = issue!.assignees!.map((assignee) => assignee.login); | ||
if (!assignedUsernames.includes(opener)) { | ||
await addAssignees(+linkedIssueNumber, [opener]); | ||
logger.debug(`Assigned pull request #${pull.number} opener to issue ${linkedIssueNumber}.`); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters