Skip to content

Commit

Permalink
feat(input): add input for custom PR title
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoHsu committed Jul 27, 2022
1 parent 0137b71 commit 6411c44
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ Before use `Deploy-Files-to-Repo` action, please use `actions/checkout` action f

| Input | required | description |
| ---------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
| source_dir | `false` | Deploy file or folder from this repository.<br/> eg. `README.md` |
| target_dir | `false` | Deploy target file or folder path into target GitHub repository.<br/>eg. `doc/README.md` of `.elastic_runner` |
| target_github_domain | `false` | Target GitHub domain.<br/>`default`: `github.com` |
| target_github_api | `false` | Target GitHub API URL.<br/>`default`: `https://api.github.com` |
| source_dir | `false` | Deploy file or folder from this repository.<br/> eg. `README.md` |
| target_dir | `false` | Deploy target file or folder path into target GitHub repository.<br/>eg. `doc/README.md` of `.elastic_runner` |
| target_github_domain | `false` | Target GitHub domain.<br/>`default`: `github.com` |
| target_github_api | `false` | Target GitHub API URL.<br/>`default`: `https://api.github.com` |
| target_personal_access_token | `true` | Target GitHub personal access token |
| target_owner | `true` | Target GitHub owner |
| target_repo | `true` | Target GitHub repository |
| target_branch | `false` | Target GitHub repository's branch. <br/>`default`: `main` |
| target_pre_copy_command | `false` | Run command on target repository before copy files flow.<br/>This command path is on `$GITHUB_WORKSPACE` |
| target_pre_commit_command | `false` | Run command on target repository before git commit.<br/>This command path is on `$GITHUB_WORKSPACE/__${TARGET_REPO}__clone__` |
| commit_msg | `false` | Custom git commit message.<br/>`default`: `Deployed $SOURCE_DIR into $TARGET_DIR from $GITHUB_REPOSITORY@${GIT_SHA_SHORT}` |
| pr_title | `false` | Custom PR title.<br/>`default`: `Deployed files from ${GITHUB_REPOSITORY}` |
| target_pr_branch | `false` | Custom PR branch.<br/>`default`: `deploy-files-to-repo--branches` |

### Usage
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ inputs:
commit_msg:
description: "Custom git commit message"
required: false
pr_title:
description: "Custom PR title"
default: "Deployed files from GITHUB_REPOSITORY"
required: false
target_pr_branch:
description: "Custom PR branch"
default: "deploy-files-to-repo--branches"
Expand Down
5 changes: 4 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ TARGET_GITHUB_DOMAIN="$INPUT_TARGET_GITHUB_DOMAIN"
TARGET_GITHUB_API="$INPUT_TARGET_GITHUB_API"
TARGET_PR_BRANCH="$INPUT_TARGET_PR_BRANCH"

DEFAULT_PR_TITLE="Deployed files from $GITHUB_REPOSITORY"
PR_TITLE="${INPUT_PR_TITLE:-$DEFAULT_PR_TITLE}"

TARGET_REPOSITORY=$TARGET_GITHUB_DOMAIN/$TARGET_OWNER/$TARGET_REPO
TARGET_REPOSITORY_URL="https://$TARGET_PERSONAL_ACCESS_TOKEN@$TARGET_REPOSITORY.git"
TARGET_CLONE_DIR="__${TARGET_REPO}__clone__"
Expand Down Expand Up @@ -64,7 +67,7 @@ if [ -n "$(git status --porcelain)" ]; then
echo "Push '$TARGET_PR_BRANCH--$TARGET_BRANCH' branch"
git push -f origin "$TARGET_PR_BRANCH--$TARGET_BRANCH"
echo "Create pull request from '$TARGET_PR_BRANCH--$TARGET_BRANCH' into '$TARGET_BRANCH'"
curl -X POST -u "GitHub Action":"$TARGET_PERSONAL_ACCESS_TOKEN" -d "{\"title\":\"Deployed files from $GITHUB_REPOSITORY\",\"body\": \"$DEFAULT_COMMIT_MSG\",\"head\": \"$TARGET_PR_BRANCH--$TARGET_BRANCH\",\"base\": \"$TARGET_BRANCH\"}" "$TARGET_GITHUB_API/repos/$TARGET_OWNER/$TARGET_REPO/pulls"
curl -X POST -u "GitHub Action":"$TARGET_PERSONAL_ACCESS_TOKEN" -d "{\"title\":\"$PR_TITLE\",\"body\": \"$DEFAULT_COMMIT_MSG\",\"head\": \"$TARGET_PR_BRANCH--$TARGET_BRANCH\",\"base\": \"$TARGET_BRANCH\"}" "$TARGET_GITHUB_API/repos/$TARGET_OWNER/$TARGET_REPO/pulls"
else
echo "No changes to push"
fi
Expand Down

0 comments on commit 6411c44

Please sign in to comment.