Skip to content

Commit

Permalink
feat: enable username inclusion as alternative to email addresses (#25)
Browse files Browse the repository at this point in the history
* feat: enable username inclusion as alternative to email addresses

* build: add test for usernames

* docs: add username to example

* docs(markdown): include and update examples

* chore(meta): update code owners

Co-authored-by: matfax <[email protected]>
  • Loading branch information
matfax and matfax authored Sep 14, 2020
1 parent 37d2233 commit 13c7017
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.github/* [email protected]
/.github/workflows/* [email protected]
/.gitignore [email protected]
/Dockerfile [email protected]
/README.md [email protected]
/action.yml [email protected]
/entrypoint.sh [email protected]
49 changes: 49 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,55 @@ jobs:
run: |
echo "::error:: the test file contained granular file references"
exit 1
- name: verify lack of username
continue-on-error: true
run: |
grep -q "@matfax" .github/CODEOWNERS.test
echo "::set-env name=username::success"
- name: fail if username is detected
if: env.username == 'success'
run: |
echo "::error:: the generated file contained a username although the input was disabled"
exit 1
- uses: actions/[email protected]
with:
name: ${{ github.job }}-owners
path: .github/CODEOWNERS.test
username:
name: test with username
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/[email protected]
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: cache docker layers
uses: satackey/[email protected]
with:
key: docker-layers-${{ hashFiles('Dockerfile') }}-${{ hashFiles('entrypoint.sh') }}
- name: update code owners
uses: ./
with:
path: .github/CODEOWNERS.test
username: true
- name: verify contents of generated file (file)
run: |
grep -q "^/.gitignore @matfax$" .github/CODEOWNERS.test
- name: verify contents of generated file (folder)
run: |
grep -q "^/.github/\* @matfax" .github/CODEOWNERS.test
- name: verify lack of email address
continue-on-error: true
run: |
grep -q "[email protected]" .github/CODEOWNERS.test
echo "::set-env name=email::success"
- name: fail if email is detected
if: env.email == 'success'
run: |
echo "::error:: the generated file still contained an email address"
exit 1
- uses: actions/[email protected]
with:
name: ${{ github.job }}-owners
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
uses: gofunky/[email protected]
with:
distribution: 25
username: true
- name: commit changed files
id: committed
uses: stefanzweifel/[email protected]
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM casperdcl/git-fame:1.12.2

RUN apk update && apk add --no-cache npm
RUN npm install --global github-username-cli

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ The default uses the path to the `.github` directory.
By default, this action checks all files in the root, but groups recursive files into their parent directories.
Set this input to any non-zero value (e.g. `true`) to enable full coverage of all recursive files.

### username

By default, this action uses the email addresses of users.
Set this input to any non-zero value (e.g. `true`) to derive the GitHub usernames and use them instead.

## Example

This is a typical example for a pull request workflow.
Expand Down Expand Up @@ -77,6 +82,7 @@ jobs:
uses: gofunky/[email protected]
with:
distribution: 25
username: true
- name: commit changed files
id: committed
uses: stefanzweifel/[email protected]
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ inputs:
Set this input to any non-zero value (e.g. `true`) to enable full coverage of all recursive files.
required: false
default: ''
username:
description: |
By default, this action uses the email addresses of users.
Set this input to any non-zero value (e.g. `true`) to derive the GitHub usernames and use them instead.
required: false
default: ''
runs:
using: docker
image: Dockerfile
21 changes: 18 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ if [ -n "$INPUT_GRANULAR" ]; then
echo "Action enabled granular file processing"
fi

identification() {
read -r email
if [ -n "$INPUT_USERNAME" ]; then
if username=$(github-username "$email" --token="$GITHUB_TOKEN");
then
echo "@$username"
else
echo "$email"
fi
else
echo "$email"
fi
}

owners() {
files=""

Expand All @@ -29,12 +43,13 @@ owners() {
fi

for file in $files; do
users=$( \
if users=$( \
git fame -eswMC --incl "$file/?[^/]*\.?[^/]*$" \
| tr '/' '|' \
| awk -v "dist=$DISTRIBUTION" -F '|' '(NR>6 && $6>=dist) {gsub(/ /, "", $2); print $2}' \
)
if [ "$?" -eq 0 ]; then
| identification
);
then
if [ -n "$users" ]; then
if [ -n "$INPUT_GRANULAR" ]; then
echo "/$file $users"
Expand Down

0 comments on commit 13c7017

Please sign in to comment.