Skip to content

Commit 3f7ee98

Browse files
jactor-risesEndBug
authored andcommitted
Gather information from The GitHub Event (#10)
* addind jq to dockerfile and unsing info from head commit * remove inputs * remove quotes from author information * author and email not from input - ignored files from intellij * setting author name and email if given as input * remove over-the-top echoing * Fix typos & formatting * Try to fix checks * Fix checks The new check works the opposite way
1 parent 7a1f5ec commit 3f7ee98

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
*.iml

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ LABEL "repository"="https://github.com/EndBug/add-and-commit"
99
LABEL "homepage"="https://github.com/EndBug/add-and-commit"
1010
LABEL "maintainer"="Federico Grandi <[email protected]>"
1111

12+
RUN apk add jq
13+
1214
COPY entrypoint.sh /entrypoint.sh
1315

1416
ENTRYPOINT ["sh", "/entrypoint.sh"]

action.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ description: 'Add & commit files from a path directly from GitHub Actions'
33

44
inputs:
55
author_name:
6-
description: 'The name of the user that will be displayed as the author of the commit'
7-
required: true
8-
default: 'Add & Commit GitHub Action'
6+
description: 'The name of the user that will be displayed as the author of the commit, defaults to author name of head commit'
7+
required: false
98
author_email:
10-
description: 'The email of the user that will be displayed as the author of the commit'
11-
required: true
12-
default: '[email protected]'
9+
description: 'The email of the user that will be displayed as the author of the commit, defaults to author email of head commit'
10+
required: false
1311
force:
1412
description: 'Whether to use the force option on git add, in order to bypass eventual gitignores'
1513
required: false

entrypoint.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
#!/bin/sh
22
set -eu
33

4+
if [ -z "$INPUT_AUTHOR_NAME" ] # Check if the variable is empty
5+
then AUTHOR_NAME=$(cat "$GITHUB_EVENT_PATH" | jq '.head_commit.author.name' | sed 's/"//g') # If so, fetch the author from the event
6+
else AUTHOR_NAME=$INPUT_AUTHOR_NAME # If not, use that value
7+
fi
8+
9+
if [ -z "$INPUT_AUTHOR_EMAIL" ]
10+
then AUTHOR_EMAIL=$(cat "$GITHUB_EVENT_PATH" | jq '.head_commit.author.email' | sed 's/"//g')
11+
else AUTHOR_EMAIL=$INPUT_AUTHOR_EMAIL
12+
fi
13+
14+
echo "Using '$AUTHOR_NAME' and '$AUTHOR_EMAIL' as author information."
15+
416
# Set up .netrc file with GitHub credentials
517
git_setup() {
618
cat <<- EOF > $HOME/.netrc
@@ -14,8 +26,8 @@ git_setup() {
1426
EOF
1527
chmod 600 $HOME/.netrc
1628

17-
git config --global user.email "[email protected]"
18-
git config --global user.name "Add & Commit GitHub Action"
29+
git config --global user.email "$AUTHOR_EMAIL"
30+
git config --global user.name "$AUTHOR_NAME"
1931
}
2032

2133
add() {
@@ -52,7 +64,7 @@ then
5264
add
5365

5466
echo "Creating commit..."
55-
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"
67+
git commit -m "$INPUT_MESSAGE" --author="$AUTHOR_NAME <$AUTHOR_EMAIL>"
5668

5769
echo "Pushing to repo..."
5870
git push --set-upstream origin "${GITHUB_REF:11}"

0 commit comments

Comments
 (0)