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

Addition of a create as draft option to action #26

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Action pull request another repository
# Action pull request another repository

This GitHub Action copies a folder from the current repository to a location in another repository and create a pull request

## Example Workflow
## Example Workflow

```yaml
name: Push File

on: push
Expand All @@ -26,8 +29,10 @@ This GitHub Action copies a folder from the current repository to a location in
user_email: 'user-name@paygo.com.br'
user_name: 'user-name'
pull_request_reviewers: 'reviewers'
```

## Variables

* source_folder: The folder to be moved. Uses the same syntax as the `cp` command. Incude the path for any files not in the repositories root directory.
* destination_repo: The repository to place the file or directory in.
* destination_folder: [optional] The folder in the destination repository to place the file in, if not the root directory.
Expand All @@ -36,13 +41,16 @@ This GitHub Action copies a folder from the current repository to a location in
* destination_base_branch: [optional] The branch into which you want your code merged. Default is `main`.
* destination_head_branch: The branch to create to push the changes. Cannot be `master` or `main`.
* pull_request_reviewers: [optional] The pull request reviewers. It can be only one (just like 'reviewer') or many (just like 'reviewer1,reviewer2,...')
* create_as_draft: [optional] Create the pull request as a draft review. If and only if string is one of `true` `1` or `yes` will set this flag to true.

## ENV
* API_TOKEN_GITHUB: You must create a personal access token in you account. Follow the link:
- [Personal access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token)

> You must select the scopes: 'repo = Full control of private repositories', 'admin:org = read:org' and 'write:discussion = Read:discussion';
**API_TOKEN_GITHUB**: You must create a personal access token in you account. Follow the link:

[Personal access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token)

> You must select the scopes: 'repo = Full control of private repositories', 'admin:org = read:org' and 'write:discussion = Read:discussion';

## Behavior Notes

The action will create any destination paths if they don't exist. It will also overwrite existing files if they already exist in the locations being copied to. It will not delete the entire destination repository.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ inputs:
pull_request_reviewers:
description: 'Pull request reviewers users'
required: false
create_as_draft:
description: 'Create pull request as draft'
required: false
default: 'false'
runs:
using: 'docker'
image: 'Dockerfile'
Expand All @@ -38,6 +42,7 @@ runs:
- ${{ inputs.destination-head-branch }}
- ${{ inputs.destination-base-branch }}
- ${{ inputs.pull-request-reviewers }}
- ${{ inputs.create-as-draft }}
branding:
icon: 'git-commit'
color: 'green'
23 changes: 22 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
set -e
set -x

function str_bool {
local str="${1:-false}"
local pat='^(true|1|yes)$'
if [[ "$str" =~ $pat ]]
then
echo 'true'
else
echo 'false'
fi
}

if [ -z "$INPUT_SOURCE_FOLDER" ]
then
echo "Source folder must be defined"
Expand All @@ -22,6 +33,15 @@ else
PULL_REQUEST_REVIEWERS='-r '$INPUT_PULL_REQUEST_REVIEWERS
fi

if [[ `str_bool "$INPUT_CREATE_AS_DRAFT"` == 'true' ]]
then
echo "CREATE_AS_DRAFT='$INPUT_CREATE_AS_DRAFT' was evaluated as true, creating as draft pr"
CREATE_AS_DRAFT=' -d '
else
echo "CREATE_AS_DRAFT='$INPUT_CREATE_AS_DRAFT' was evaluated as false"
CREATE_AS_DRAFT=''
fi

CLONE_DIR=$(mktemp -d)

echo "Setting git variables"
Expand Down Expand Up @@ -50,7 +70,8 @@ then
-b $INPUT_DESTINATION_HEAD_BRANCH \
-B $INPUT_DESTINATION_BASE_BRANCH \
-H $INPUT_DESTINATION_HEAD_BRANCH \
$PULL_REQUEST_REVIEWERS
$PULL_REQUEST_REVIEWERS \
$CREATE_AS_DRAFT
else
echo "No changes detected"
fi