This repository was archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Assign PR owner to linked issue #273
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74c92e9
feat: add pull request to processor
seprintour d996c04
fix: add pull requests to watch and processor
seprintour b1cb405
feat: loop pr and find issue (wrong issue linked by api)
seprintour de0b820
feat: auto-link pr to issue done
seprintour 3c14120
fix: remove unused
seprintour 8de6773
fix: move helpers to helper file
seprintour dfae2ab
Merge branch 'development' into link-pr-to-issue
seprintour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,73 @@ | ||
import { Context } from "probot"; | ||
import { getBotContext, getLogger } from "../../bindings"; | ||
import { addAssignees } from "../../helpers"; | ||
import { gitLinkedIssueParser } from "../../helpers/parser"; | ||
import { Payload } from "../../types"; | ||
|
||
// Use `context.octokit.rest` to get the pull requests for the repository | ||
export const getPullRequests = async (context: Context) => { | ||
const logger = getLogger(); | ||
const payload = context.payload as Payload; | ||
try { | ||
const { data: pulls } = await context.octokit.rest.pulls.list({ | ||
seprintour marked this conversation as resolved.
Show resolved
Hide resolved
|
||
owner: payload.repository.owner.login, | ||
repo: payload.repository.name, | ||
state: "open", | ||
}); | ||
return pulls; | ||
} catch (e: unknown) { | ||
logger.debug(`Fetching pull requests failed!, reason: ${e}`); | ||
return []; | ||
} | ||
}; | ||
|
||
// 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; | ||
const { data: issue } = await context.octokit.rest.issues.get({ | ||
seprintour marked this conversation as resolved.
Show resolved
Hide resolved
|
||
owner: payload.repository.owner.login, | ||
repo: payload.repository.name, | ||
issue_number: +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}.`); | ||
console.log(`Assigned pull request #${pull.number} opener to issue ${linkedIssueNumber}.`); | ||
seprintour marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.