Add argument to specify name used in commits

This commit is contained in:
James C 2021-04-29 06:06:40 +01:00
parent 5c472514b3
commit 637a257cca
No known key found for this signature in database
GPG Key ID: B1B5CE18EE508FB2
3 changed files with 19 additions and 5 deletions

View File

@ -15,7 +15,7 @@ There are different variables to setup the behaviour:
From the repository that this Git Action is executed the directory that contains the files to be pushed into the repository. From the repository that this Git Action is executed the directory that contains the files to be pushed into the repository.
### `destination-github-username` (argument) ### `destination-github-username` (argument)
For the repository `https://github.com/cpina/push-to-another-repository-output` is `cpina`. It's also used for the `Author:` in the generated git messages. For the repository `https://github.com/cpina/push-to-another-repository-output` is `cpina`.
### `destination-repository-name` (argument) ### `destination-repository-name` (argument)
For the repository `https://github.com/cpina/push-to-another-repository-output` is `push-to-another-repository-output` For the repository `https://github.com/cpina/push-to-another-repository-output` is `push-to-another-repository-output`
@ -25,6 +25,9 @@ For the repository `https://github.com/cpina/push-to-another-repository-output`
### `user-email` (argument) ### `user-email` (argument)
The email that will be used for the commit in the destination-repository-name. The email that will be used for the commit in the destination-repository-name.
### `user-name` (argument) [optional]
The name that will be used for the commit in the destination-repository-name. If not specified, the `destination-github-username` will be used instead.
### `destination-repository-username` (argument) [optional] ### `destination-repository-username` (argument) [optional]
The Username/Organization for the destination repository, if different from `destination-github-username`. For the repository `https://github.com/cpina/push-to-another-repository-output` is `cpina`. The Username/Organization for the destination repository, if different from `destination-github-username`. For the repository `https://github.com/cpina/push-to-another-repository-output` is `cpina`.

View File

@ -13,6 +13,10 @@ inputs:
user-email: user-email:
description: 'Email for the git commit' description: 'Email for the git commit'
required: true required: true
user-name:
description: '[Optional] Name for the git commit. Defaults to the destination username/organization name'
required: false
default: ''
destination-repository-username: destination-repository-username:
description: '[Optional] Username/organization for the destination repository' description: '[Optional] Username/organization for the destination repository'
required: false required: false
@ -33,6 +37,7 @@ runs:
- ${{ inputs.destination-github-username }} - ${{ inputs.destination-github-username }}
- ${{ inputs.destination-repository-name }} - ${{ inputs.destination-repository-name }}
- ${{ inputs.user-email }} - ${{ inputs.user-email }}
- ${{ inputs.user-name }}
- ${{ inputs.destination-repository-username }} - ${{ inputs.destination-repository-username }}
- ${{ inputs.target-branch }} - ${{ inputs.target-branch }}
- ${{ inputs.commit-message }} - ${{ inputs.commit-message }}

View File

@ -8,21 +8,27 @@ SOURCE_DIRECTORY="$1"
DESTINATION_GITHUB_USERNAME="$2" DESTINATION_GITHUB_USERNAME="$2"
DESTINATION_REPOSITORY_NAME="$3" DESTINATION_REPOSITORY_NAME="$3"
USER_EMAIL="$4" USER_EMAIL="$4"
DESTINATION_REPOSITORY_USERNAME="$5" USER_NAME="$5"
TARGET_BRANCH="$6" DESTINATION_REPOSITORY_USERNAME="$6"
COMMIT_MESSAGE="$7" TARGET_BRANCH="$7"
COMMIT_MESSAGE="$8"
if [ -z "$DESTINATION_REPOSITORY_USERNAME" ] if [ -z "$DESTINATION_REPOSITORY_USERNAME" ]
then then
DESTINATION_REPOSITORY_USERNAME="$DESTINATION_GITHUB_USERNAME" DESTINATION_REPOSITORY_USERNAME="$DESTINATION_GITHUB_USERNAME"
fi fi
if [ -z "$USER_NAME" ]
then
USER_NAME="$DESTINATION_GITHUB_USERNAME"
fi
CLONE_DIR=$(mktemp -d) CLONE_DIR=$(mktemp -d)
echo "Cloning destination git repository" echo "Cloning destination git repository"
# Setup git # Setup git
git config --global user.email "$USER_EMAIL" git config --global user.email "$USER_EMAIL"
git config --global user.name "$DESTINATION_GITHUB_USERNAME" git config --global user.name "$USER_NAME"
git clone --single-branch --branch "$TARGET_BRANCH" "https://$API_TOKEN_GITHUB@github.com/$DESTINATION_REPOSITORY_USERNAME/$DESTINATION_REPOSITORY_NAME.git" "$CLONE_DIR" git clone --single-branch --branch "$TARGET_BRANCH" "https://$API_TOKEN_GITHUB@github.com/$DESTINATION_REPOSITORY_USERNAME/$DESTINATION_REPOSITORY_NAME.git" "$CLONE_DIR"
ls -la "$CLONE_DIR" ls -la "$CLONE_DIR"