Compare commits

...

4 Commits

Author SHA1 Message Date
Peter Evans
34371f09e5 Merge pull request #719 from peter-evans/add-to-lists
fix: add to labels and assignees instead of resetting
2021-02-08 10:19:41 +09:00
Peter Evans
c27ea51ae0 fix: add to labels and assignees instead of resetting 2021-02-08 09:32:46 +09:00
Peter Evans
5e9d0ee9ea Merge pull request #712 from peter-evans/operation-output
feat: add pull-request-operation output
2021-02-01 10:28:29 +09:00
Peter Evans
b5f41d9b08 feat: add pull-request-operation output 2021-02-01 09:57:11 +09:00
5 changed files with 8021 additions and 46 deletions

View File

@@ -66,7 +66,13 @@ All inputs are **optional**. If not set, sensible defaults will be used.
### Action outputs ### Action outputs
The pull request number and URL are available as step outputs. The following outputs can be used by subsequent workflow steps.
- `pull-request-number` - The pull request number.
- `pull-request-url` - The URL of the pull request.
- `pull-request-operation` - The pull request operation performed by the action, `created`, `updated` or `closed`.
Step outputs can be accessed as in the following example.
Note that in order to read the step outputs the action step must have an id. Note that in order to read the step outputs the action step must have an id.
```yml ```yml

47
dist/index.js vendored
View File

@@ -391,7 +391,20 @@ function createPullRequest(inputs) {
inputs.base = result.base; inputs.base = result.base;
if (result.hasDiffWithBase) { if (result.hasDiffWithBase) {
// Create or update the pull request // Create or update the pull request
yield githubHelper.createOrUpdatePullRequest(inputs, baseRemote.repository, branchRepository); const pull = yield githubHelper.createOrUpdatePullRequest(inputs, baseRemote.repository, branchRepository);
// Set outputs
core.startGroup('Setting outputs');
core.setOutput('pull-request-number', pull.number);
core.setOutput('pull-request-url', pull.html_url);
if (pull.created) {
core.setOutput('pull-request-operation', 'created');
}
else if (result.action == 'updated') {
core.setOutput('pull-request-operation', 'updated');
}
// Deprecated
core.exportVariable('PULL_REQUEST_NUMBER', pull.number);
core.endGroup();
} }
else { else {
// There is no longer a diff with the base // There is no longer a diff with the base
@@ -406,6 +419,10 @@ function createPullRequest(inputs) {
branchRemoteName, branchRemoteName,
`refs/heads/${inputs.branch}` `refs/heads/${inputs.branch}`
]); ]);
// Set outputs
core.startGroup('Setting outputs');
core.setOutput('pull-request-operation', 'closed');
core.endGroup();
} }
} }
} }
@@ -919,7 +936,8 @@ class GitHubHelper {
core.info(`Created pull request #${pull.number} (${headBranch} => ${inputs.base})`); core.info(`Created pull request #${pull.number} (${headBranch} => ${inputs.base})`);
return { return {
number: pull.number, number: pull.number,
html_url: pull.html_url html_url: pull.html_url,
created: true
}; };
} }
catch (e) { catch (e) {
@@ -937,7 +955,8 @@ class GitHubHelper {
core.info(`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`); core.info(`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`);
return { return {
number: pull.number, number: pull.number,
html_url: pull.html_url html_url: pull.html_url,
created: false
}; };
}); });
} }
@@ -956,29 +975,20 @@ class GitHubHelper {
const headBranch = `${headOwner}:${inputs.branch}`; const headBranch = `${headOwner}:${inputs.branch}`;
// Create or update the pull request // Create or update the pull request
const pull = yield this.createOrUpdate(inputs, baseRepository, headBranch); const pull = yield this.createOrUpdate(inputs, baseRepository, headBranch);
// Set outputs // Apply milestone
core.startGroup('Setting outputs');
core.setOutput('pull-request-number', pull.number);
core.setOutput('pull-request-url', pull.html_url);
// Deprecated
core.exportVariable('PULL_REQUEST_NUMBER', pull.number);
core.endGroup();
// Set milestone, labels and assignees
const updateIssueParams = {};
if (inputs.milestone) { if (inputs.milestone) {
updateIssueParams['milestone'] = inputs.milestone;
core.info(`Applying milestone '${inputs.milestone}'`); core.info(`Applying milestone '${inputs.milestone}'`);
yield this.octokit.issues.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number, milestone: inputs.milestone }));
} }
// Apply labels
if (inputs.labels.length > 0) { if (inputs.labels.length > 0) {
updateIssueParams['labels'] = inputs.labels;
core.info(`Applying labels '${inputs.labels}'`); core.info(`Applying labels '${inputs.labels}'`);
yield this.octokit.issues.addLabels(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number, labels: inputs.labels }));
} }
// Apply assignees
if (inputs.assignees.length > 0) { if (inputs.assignees.length > 0) {
updateIssueParams['assignees'] = inputs.assignees;
core.info(`Applying assignees '${inputs.assignees}'`); core.info(`Applying assignees '${inputs.assignees}'`);
} yield this.octokit.issues.addAssignees(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number, labels: inputs.assignees }));
if (Object.keys(updateIssueParams).length > 0) {
yield this.octokit.issues.update(Object.assign(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number }), updateIssueParams));
} }
// Request reviewers and team reviewers // Request reviewers and team reviewers
const requestReviewersParams = {}; const requestReviewersParams = {};
@@ -1003,6 +1013,7 @@ class GitHubHelper {
} }
} }
} }
return pull;
}); });
} }
} }

7940
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -195,11 +195,24 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
if (result.hasDiffWithBase) { if (result.hasDiffWithBase) {
// Create or update the pull request // Create or update the pull request
await githubHelper.createOrUpdatePullRequest( const pull = await githubHelper.createOrUpdatePullRequest(
inputs, inputs,
baseRemote.repository, baseRemote.repository,
branchRepository branchRepository
) )
// Set outputs
core.startGroup('Setting outputs')
core.setOutput('pull-request-number', pull.number)
core.setOutput('pull-request-url', pull.html_url)
if (pull.created) {
core.setOutput('pull-request-operation', 'created')
} else if (result.action == 'updated') {
core.setOutput('pull-request-operation', 'updated')
}
// Deprecated
core.exportVariable('PULL_REQUEST_NUMBER', pull.number)
core.endGroup()
} else { } else {
// There is no longer a diff with the base // There is no longer a diff with the base
// Check we are in a state where a branch exists // Check we are in a state where a branch exists
@@ -215,6 +228,10 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
branchRemoteName, branchRemoteName,
`refs/heads/${inputs.branch}` `refs/heads/${inputs.branch}`
]) ])
// Set outputs
core.startGroup('Setting outputs')
core.setOutput('pull-request-operation', 'closed')
core.endGroup()
} }
} }
} }

View File

@@ -13,6 +13,7 @@ interface Repository {
interface Pull { interface Pull {
number: number number: number
html_url: string html_url: string
created: boolean
} }
export class GitHubHelper { export class GitHubHelper {
@@ -55,7 +56,8 @@ export class GitHubHelper {
) )
return { return {
number: pull.number, number: pull.number,
html_url: pull.html_url html_url: pull.html_url,
created: true
} }
} catch (e) { } catch (e) {
if ( if (
@@ -87,7 +89,8 @@ export class GitHubHelper {
) )
return { return {
number: pull.number, number: pull.number,
html_url: pull.html_url html_url: pull.html_url,
created: false
} }
} }
@@ -107,40 +110,38 @@ export class GitHubHelper {
inputs: Inputs, inputs: Inputs,
baseRepository: string, baseRepository: string,
headRepository: string headRepository: string
): Promise<void> { ): Promise<Pull> {
const [headOwner] = headRepository.split('/') const [headOwner] = headRepository.split('/')
const headBranch = `${headOwner}:${inputs.branch}` const headBranch = `${headOwner}:${inputs.branch}`
// Create or update the pull request // Create or update the pull request
const pull = await this.createOrUpdate(inputs, baseRepository, headBranch) const pull = await this.createOrUpdate(inputs, baseRepository, headBranch)
// Set outputs // Apply milestone
core.startGroup('Setting outputs')
core.setOutput('pull-request-number', pull.number)
core.setOutput('pull-request-url', pull.html_url)
// Deprecated
core.exportVariable('PULL_REQUEST_NUMBER', pull.number)
core.endGroup()
// Set milestone, labels and assignees
const updateIssueParams = {}
if (inputs.milestone) { if (inputs.milestone) {
updateIssueParams['milestone'] = inputs.milestone
core.info(`Applying milestone '${inputs.milestone}'`) core.info(`Applying milestone '${inputs.milestone}'`)
}
if (inputs.labels.length > 0) {
updateIssueParams['labels'] = inputs.labels
core.info(`Applying labels '${inputs.labels}'`)
}
if (inputs.assignees.length > 0) {
updateIssueParams['assignees'] = inputs.assignees
core.info(`Applying assignees '${inputs.assignees}'`)
}
if (Object.keys(updateIssueParams).length > 0) {
await this.octokit.issues.update({ await this.octokit.issues.update({
...this.parseRepository(baseRepository), ...this.parseRepository(baseRepository),
issue_number: pull.number, issue_number: pull.number,
...updateIssueParams milestone: inputs.milestone
})
}
// Apply labels
if (inputs.labels.length > 0) {
core.info(`Applying labels '${inputs.labels}'`)
await this.octokit.issues.addLabels({
...this.parseRepository(baseRepository),
issue_number: pull.number,
labels: inputs.labels
})
}
// Apply assignees
if (inputs.assignees.length > 0) {
core.info(`Applying assignees '${inputs.assignees}'`)
await this.octokit.issues.addAssignees({
...this.parseRepository(baseRepository),
issue_number: pull.number,
labels: inputs.assignees
}) })
} }
@@ -169,5 +170,7 @@ export class GitHubHelper {
} }
} }
} }
return pull
} }
} }