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: action outputs #352

Merged
merged 5 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ If there are changes, it does the following
4. Pushes the local changes to remote using the branch configured in the `branch` input.
5. Creates a pull request using the `title` and `body` inputs. If a pull request exists for the branch, it's checked out locally, rebased with `-XTheirs` and pushed with `--force` to update the pull request with the new changes.

The actions outputs following properties:

- `pr-number` - number of created/updated PR
- `result` - `created` or `updated` depending the PR was created or only updated

AuHau marked this conversation as resolved.
Show resolved Hide resolved
The action is written in JavaScript. [Learn how to create your own](https://help.github.com/en/articles/creating-a-javascript-action).

## Who is using it
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ inputs:
description: "Enable auto merge for pull request. Requires auto merging to be enabled in repository settings"
required: false

outputs:
pr-number:
description: "Number of the created/updated PR"
result:
description: "'updated' or 'created' based if the PR was created or updated"

runs:
using: "node12"
main: "dist/index.js"
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@ async function main() {
});

if (data.total_count > 0) {
const prInfo = data.items[0]; // Assuming there is only one PR for given branch

core.setOutput(`pr-number`, prInfo.number);
core.setOutput(`result`, `updated`);
core.info(
`Existing pull request for branch "${inputs.branch}" updated: ${data.items.html_url}`
`Existing pull request for branch "${inputs.branch}" updated: ${prInfo.html_url}`
);
return;
}
Expand All @@ -171,6 +175,9 @@ async function main() {

core.info(`Pull request created: ${html_url} (#${number})`);

core.setOutput(`pr-number`, number);
core.setOutput(`result`, `created`);

if (inputs.labels) {
core.debug(`Adding labels: ${inputs.labels}`);
const labels = inputs.labels.trim().split(/\s*,\s*/);
Expand Down