From cfb5cb594972abdf7f1fd0ace1cb3d00b1daeb34 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Wed, 4 Nov 2020 16:23:02 +0000 Subject: [PATCH] Allow to pass the commit message --- README.md | 5 +++++ action.yml | 4 ++++ entrypoint.sh | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f8a999..62a66bb 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,11 @@ The Username/Organization for the destination repository, if different from `des ### `target-branch` (argument) [optional] The branch name for the destination repository, if different from `master`. +### `commit-message` (argument) [optional] +The commit message to be used in the output repository. Optional and defaults to "Update from $REPOSITORY_URL@commit". + +The string `ORIGIN_COMMIT` is replaced by `$REPOSITORY_URL@commit`. + ### `API_TOKEN_GITHUB` (environment) E.g.: `API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}` diff --git a/action.yml b/action.yml index 387dd0f..0ec4ae4 100644 --- a/action.yml +++ b/action.yml @@ -21,6 +21,9 @@ inputs: description: '[Optional] set target branch name for the destination repository. Defaults to "master"' default: 'master' required: false + commit-message: '[Optional] commit message for the output repository. ORIGIN_COMMIT is replaced by the URL@commit in the origin repo' + default: 'Update from ORIGIN_COMMIT' + required: false runs: using: 'docker' image: 'Dockerfile' @@ -31,6 +34,7 @@ runs: - ${{ inputs.user-email }} - ${{ inputs.destination-repository-username }} - ${{ inputs.target-branch }} + - ${{ inputs.commit-message }} branding: icon: 'git-commit' color: 'green' diff --git a/entrypoint.sh b/entrypoint.sh index feeec2e..57e7ed8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,6 +10,7 @@ DESTINATION_REPOSITORY_NAME="$3" USER_EMAIL="$4" DESTINATION_REPOSITORY_USERNAME="$5" TARGET_BRANCH="$6" +COMMIT_MESSAGE="$7" if [ -z "$DESTINATION_REPOSITORY_USERNAME" ] then @@ -36,9 +37,13 @@ cd "$CLONE_DIR" ls -la echo "Adding git commit" + +ORIGIN_COMMIT="https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" +COMMIT_MESSAGE=$(echo "$COMMIT_MESSAGE" | sed "s/ORIGIN_COMMIT/$ORIGIN_COMMIT") + git add . git status -git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" +git commit --message "$COMMIT_MESSAGE" echo "Pushing git commit" git push origin "$TARGET_BRANCH"