Merge pull request #27 from JamesMCo/main

Add argument to specify name used in commits
This commit is contained in:
Carles Pina Estany 2021-04-29 23:45:48 +02:00 committed by GitHub
commit 940a2857e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.
### `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)
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)
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]
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:
description: 'Email for the git commit'
required: true
user-name:
description: '[Optional] Name for the git commit. Defaults to the destination username/organization name'
required: false
default: ''
destination-repository-username:
description: '[Optional] Username/organization for the destination repository'
required: false
@ -33,6 +37,7 @@ runs:
- ${{ inputs.destination-github-username }}
- ${{ inputs.destination-repository-name }}
- ${{ inputs.user-email }}
- ${{ inputs.user-name }}
- ${{ inputs.destination-repository-username }}
- ${{ inputs.target-branch }}
- ${{ inputs.commit-message }}

View File

@ -8,21 +8,27 @@ SOURCE_DIRECTORY="$1"
DESTINATION_GITHUB_USERNAME="$2"
DESTINATION_REPOSITORY_NAME="$3"
USER_EMAIL="$4"
DESTINATION_REPOSITORY_USERNAME="$5"
TARGET_BRANCH="$6"
COMMIT_MESSAGE="$7"
USER_NAME="$5"
DESTINATION_REPOSITORY_USERNAME="$6"
TARGET_BRANCH="$7"
COMMIT_MESSAGE="$8"
if [ -z "$DESTINATION_REPOSITORY_USERNAME" ]
then
DESTINATION_REPOSITORY_USERNAME="$DESTINATION_GITHUB_USERNAME"
fi
if [ -z "$USER_NAME" ]
then
USER_NAME="$DESTINATION_GITHUB_USERNAME"
fi
CLONE_DIR=$(mktemp -d)
echo "Cloning destination git repository"
# Setup git
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"
ls -la "$CLONE_DIR"