Merge pull request #587 from peter-evans/url-output
feat: output the pull request url
This commit is contained in:
commit
da928d5fcc
4 changed files with 42 additions and 22 deletions
1
.github/workflows/cpr-example-command.yml
vendored
1
.github/workflows/cpr-example-command.yml
vendored
|
@ -39,6 +39,7 @@ jobs:
|
||||||
- name: Check output
|
- name: Check output
|
||||||
run: |
|
run: |
|
||||||
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
|
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
|
||||||
|
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
|
||||||
|
|
||||||
- name: Add reaction
|
- name: Add reaction
|
||||||
uses: peter-evans/create-or-update-comment@v1
|
uses: peter-evans/create-or-update-comment@v1
|
||||||
|
|
|
@ -66,8 +66,8 @@ All inputs are **optional**. If not set, sensible defaults will be used.
|
||||||
|
|
||||||
### Action outputs
|
### Action outputs
|
||||||
|
|
||||||
The pull request number is output as a step output.
|
The pull request number and URL are available as step outputs.
|
||||||
Note that in order to read the step output 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
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
|
@ -76,6 +76,7 @@ Note that in order to read the step output the action step must have an id.
|
||||||
- name: Check outputs
|
- name: Check outputs
|
||||||
run: |
|
run: |
|
||||||
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
|
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
|
||||||
|
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Action behaviour
|
### Action behaviour
|
||||||
|
@ -196,9 +197,10 @@ jobs:
|
||||||
milestone: 1
|
milestone: 1
|
||||||
draft: false
|
draft: false
|
||||||
|
|
||||||
- name: Check output
|
- name: Check outputs
|
||||||
run: |
|
run: |
|
||||||
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
|
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
|
||||||
|
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
|
||||||
```
|
```
|
||||||
|
|
||||||
An example based on the above reference configuration creates pull requests that look like this:
|
An example based on the above reference configuration creates pull requests that look like this:
|
||||||
|
|
22
dist/index.js
vendored
22
dist/index.js
vendored
|
@ -906,7 +906,10 @@ class GitHubHelper {
|
||||||
try {
|
try {
|
||||||
const { data: pull } = yield this.octokit.pulls.create(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { title: inputs.title, head: headBranch, base: inputs.base, body: inputs.body, draft: inputs.draft }));
|
const { data: pull } = yield this.octokit.pulls.create(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { title: inputs.title, head: headBranch, base: inputs.base, body: inputs.body, draft: inputs.draft }));
|
||||||
core.info(`Created pull request #${pull.number} (${headBranch} => ${inputs.base})`);
|
core.info(`Created pull request #${pull.number} (${headBranch} => ${inputs.base})`);
|
||||||
return pull.number;
|
return {
|
||||||
|
number: pull.number,
|
||||||
|
html_url: pull.html_url
|
||||||
|
};
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (!e.message ||
|
if (!e.message ||
|
||||||
|
@ -918,7 +921,10 @@ class GitHubHelper {
|
||||||
const { data: pulls } = yield this.octokit.pulls.list(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', head: headBranch, base: inputs.base }));
|
const { data: pulls } = yield this.octokit.pulls.list(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', head: headBranch, base: inputs.base }));
|
||||||
const { data: pull } = yield this.octokit.pulls.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pulls[0].number, title: inputs.title, body: inputs.body, draft: inputs.draft }));
|
const { data: pull } = yield this.octokit.pulls.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pulls[0].number, title: inputs.title, body: inputs.body, draft: inputs.draft }));
|
||||||
core.info(`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`);
|
core.info(`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`);
|
||||||
return pull.number;
|
return {
|
||||||
|
number: pull.number,
|
||||||
|
html_url: pull.html_url
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getRepositoryParent(headRepository) {
|
getRepositoryParent(headRepository) {
|
||||||
|
@ -935,11 +941,13 @@ class GitHubHelper {
|
||||||
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 pullNumber = yield this.createOrUpdate(inputs, baseRepository, headBranch);
|
const pull = yield this.createOrUpdate(inputs, baseRepository, headBranch);
|
||||||
// Set outputs
|
// Set outputs
|
||||||
core.startGroup('Setting outputs');
|
core.startGroup('Setting outputs');
|
||||||
core.setOutput('pull-request-number', pullNumber);
|
core.setOutput('pull-request-number', pull.number);
|
||||||
core.exportVariable('PULL_REQUEST_NUMBER', pullNumber);
|
core.setOutput('pull-request-url', pull.html_url);
|
||||||
|
// Deprecated
|
||||||
|
core.exportVariable('PULL_REQUEST_NUMBER', pull.number);
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
// Set milestone, labels and assignees
|
// Set milestone, labels and assignees
|
||||||
const updateIssueParams = {};
|
const updateIssueParams = {};
|
||||||
|
@ -956,7 +964,7 @@ class GitHubHelper {
|
||||||
core.info(`Applying assignees '${inputs.assignees}'`);
|
core.info(`Applying assignees '${inputs.assignees}'`);
|
||||||
}
|
}
|
||||||
if (Object.keys(updateIssueParams).length > 0) {
|
if (Object.keys(updateIssueParams).length > 0) {
|
||||||
yield this.octokit.issues.update(Object.assign(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pullNumber }), updateIssueParams));
|
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 = {};
|
||||||
|
@ -970,7 +978,7 @@ class GitHubHelper {
|
||||||
}
|
}
|
||||||
if (Object.keys(requestReviewersParams).length > 0) {
|
if (Object.keys(requestReviewersParams).length > 0) {
|
||||||
try {
|
try {
|
||||||
yield this.octokit.pulls.requestReviewers(Object.assign(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pullNumber }), requestReviewersParams));
|
yield this.octokit.pulls.requestReviewers(Object.assign(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pull.number }), requestReviewersParams));
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (e.message && e.message.includes(ERROR_PR_REVIEW_FROM_AUTHOR)) {
|
if (e.message && e.message.includes(ERROR_PR_REVIEW_FROM_AUTHOR)) {
|
||||||
|
|
|
@ -10,6 +10,11 @@ interface Repository {
|
||||||
repo: string
|
repo: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Pull {
|
||||||
|
number: number
|
||||||
|
html_url: string
|
||||||
|
}
|
||||||
|
|
||||||
export class GitHubHelper {
|
export class GitHubHelper {
|
||||||
private octokit: InstanceType<typeof Octokit>
|
private octokit: InstanceType<typeof Octokit>
|
||||||
|
|
||||||
|
@ -33,7 +38,7 @@ export class GitHubHelper {
|
||||||
inputs: Inputs,
|
inputs: Inputs,
|
||||||
baseRepository: string,
|
baseRepository: string,
|
||||||
headBranch: string
|
headBranch: string
|
||||||
): Promise<number> {
|
): Promise<Pull> {
|
||||||
// Try to create the pull request
|
// Try to create the pull request
|
||||||
try {
|
try {
|
||||||
const {data: pull} = await this.octokit.pulls.create({
|
const {data: pull} = await this.octokit.pulls.create({
|
||||||
|
@ -47,7 +52,10 @@ export class GitHubHelper {
|
||||||
core.info(
|
core.info(
|
||||||
`Created pull request #${pull.number} (${headBranch} => ${inputs.base})`
|
`Created pull request #${pull.number} (${headBranch} => ${inputs.base})`
|
||||||
)
|
)
|
||||||
return pull.number
|
return {
|
||||||
|
number: pull.number,
|
||||||
|
html_url: pull.html_url
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (
|
if (
|
||||||
!e.message ||
|
!e.message ||
|
||||||
|
@ -74,7 +82,10 @@ export class GitHubHelper {
|
||||||
core.info(
|
core.info(
|
||||||
`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`
|
`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`
|
||||||
)
|
)
|
||||||
return pull.number
|
return {
|
||||||
|
number: pull.number,
|
||||||
|
html_url: pull.html_url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRepositoryParent(headRepository: string): Promise<string> {
|
async getRepositoryParent(headRepository: string): Promise<string> {
|
||||||
|
@ -98,16 +109,14 @@ export 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 pullNumber = await this.createOrUpdate(
|
const pull = await this.createOrUpdate(inputs, baseRepository, headBranch)
|
||||||
inputs,
|
|
||||||
baseRepository,
|
|
||||||
headBranch
|
|
||||||
)
|
|
||||||
|
|
||||||
// Set outputs
|
// Set outputs
|
||||||
core.startGroup('Setting outputs')
|
core.startGroup('Setting outputs')
|
||||||
core.setOutput('pull-request-number', pullNumber)
|
core.setOutput('pull-request-number', pull.number)
|
||||||
core.exportVariable('PULL_REQUEST_NUMBER', pullNumber)
|
core.setOutput('pull-request-url', pull.html_url)
|
||||||
|
// Deprecated
|
||||||
|
core.exportVariable('PULL_REQUEST_NUMBER', pull.number)
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|
||||||
// Set milestone, labels and assignees
|
// Set milestone, labels and assignees
|
||||||
|
@ -127,7 +136,7 @@ export class GitHubHelper {
|
||||||
if (Object.keys(updateIssueParams).length > 0) {
|
if (Object.keys(updateIssueParams).length > 0) {
|
||||||
await this.octokit.issues.update({
|
await this.octokit.issues.update({
|
||||||
...this.parseRepository(baseRepository),
|
...this.parseRepository(baseRepository),
|
||||||
issue_number: pullNumber,
|
issue_number: pull.number,
|
||||||
...updateIssueParams
|
...updateIssueParams
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -146,7 +155,7 @@ export class GitHubHelper {
|
||||||
try {
|
try {
|
||||||
await this.octokit.pulls.requestReviewers({
|
await this.octokit.pulls.requestReviewers({
|
||||||
...this.parseRepository(baseRepository),
|
...this.parseRepository(baseRepository),
|
||||||
pull_number: pullNumber,
|
pull_number: pull.number,
|
||||||
...requestReviewersParams
|
...requestReviewersParams
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in a new issue