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

feat: allow inheriting or overwriting assignee #3

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inputs:
pr-assignee:
description:
'(optional) User ID to be assigned to the created PR. Will use the
author of the original PR by default'
assignee of the original PR by default'
required: false
default: ''
pr-labels:
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 21 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import { Label, PullRequest } from '@octokit/webhooks-types'
import { addLabels, createPullRequest } from './pr'
import { addAssignee, addLabels, createPullRequest } from './pr'
import {
cherryPickChangesToNewBranch,
configureGitUser,
Expand Down Expand Up @@ -37,9 +37,9 @@ export async function run(): Promise<void> {
const githubToken = core.getInput('pr-creator-token')
const submoduleName = core.getInput('submodule-name')
let prAssignee = core.getInput('pr-assignee')
if (prAssignee === '') {
// Use the author of the original PR as the assignee of the cherry-pick
prAssignee = mergedPR.user.login
if (prAssignee === '' && mergedPR.assignee != null) {
// Use the assignee of the original PR as the assignee of the cherry-pick
prAssignee = mergedPR.assignee.login
}
const labelsInput = core.getInput('pr-labels')
let addedLabels: string[] = []
Expand Down Expand Up @@ -112,6 +112,8 @@ export async function run(): Promise<void> {
inheritedLabels.concat(addedLabels)
)

await addAssignee(githubToken, resultPrNumber, prAssignee)

core.setOutput('pr-number', resultPrNumber)
} catch (error) {
// Fail the workflow run if an error occurs
Expand Down
20 changes: 20 additions & 0 deletions src/pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,23 @@ export async function addLabels(
labels: labelsToAdd
})
}

export async function addAssignee(
githubToken: string,
issueNumber: number,
assigneeUserName: string
): Promise<void> {
if (assigneeUserName.length === 0) {
console.info('Skipping addition of assignee, as passed value is empty')
return
}
const octokit = github.getOctokit(githubToken)
const repoOwner = github.context.repo.owner
const repoName = github.context.repo.repo
await octokit.rest.issues.addAssignees({
owner: repoOwner,
repo: repoName,
issue_number: issueNumber,
assignees: [assigneeUserName]
})
}
Loading