Skip to content

Commit 13c7017

Browse files
authored
feat: enable username inclusion as alternative to email addresses (#25)
* 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]>
1 parent 37d2233 commit 13c7017

File tree

7 files changed

+84
-3
lines changed

7 files changed

+84
-3
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
22
/.github/workflows/* [email protected]
33
/.gitignore [email protected]
4+
/Dockerfile [email protected]
45
56
/action.yml [email protected]
67
/entrypoint.sh [email protected]

.github/workflows/build.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,55 @@ jobs:
4141
run: |
4242
echo "::error:: the test file contained granular file references"
4343
exit 1
44+
- name: verify lack of username
45+
continue-on-error: true
46+
run: |
47+
grep -q "@matfax" .github/CODEOWNERS.test
48+
echo "::set-env name=username::success"
49+
- name: fail if username is detected
50+
if: env.username == 'success'
51+
run: |
52+
echo "::error:: the generated file contained a username although the input was disabled"
53+
exit 1
54+
- uses: actions/[email protected]
55+
with:
56+
name: ${{ github.job }}-owners
57+
path: .github/CODEOWNERS.test
58+
username:
59+
name: test with username
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: checkout code
63+
uses: actions/[email protected]
64+
with:
65+
repository: ${{ github.event.pull_request.head.repo.full_name }}
66+
ref: ${{ github.head_ref }}
67+
fetch-depth: 0
68+
- name: cache docker layers
69+
uses: satackey/[email protected]
70+
with:
71+
key: docker-layers-${{ hashFiles('Dockerfile') }}-${{ hashFiles('entrypoint.sh') }}
72+
- name: update code owners
73+
uses: ./
74+
with:
75+
path: .github/CODEOWNERS.test
76+
username: true
77+
- name: verify contents of generated file (file)
78+
run: |
79+
grep -q "^/.gitignore @matfax$" .github/CODEOWNERS.test
80+
- name: verify contents of generated file (folder)
81+
run: |
82+
grep -q "^/.github/\* @matfax" .github/CODEOWNERS.test
83+
- name: verify lack of email address
84+
continue-on-error: true
85+
run: |
86+
grep -q "[email protected]" .github/CODEOWNERS.test
87+
echo "::set-env name=email::success"
88+
- name: fail if email is detected
89+
if: env.email == 'success'
90+
run: |
91+
echo "::error:: the generated file still contained an email address"
92+
exit 1
4493
- uses: actions/[email protected]
4594
with:
4695
name: ${{ github.job }}-owners

.github/workflows/example.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
uses: gofunky/[email protected]
3434
with:
3535
distribution: 25
36+
username: true
3637
- name: commit changed files
3738
id: committed
3839
uses: stefanzweifel/[email protected]

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM casperdcl/git-fame:1.12.2
22

3+
RUN apk update && apk add --no-cache npm
4+
RUN npm install --global github-username-cli
5+
36
COPY entrypoint.sh /entrypoint.sh
47
RUN chmod +x /entrypoint.sh
58

README.md

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

36+
### username
37+
38+
By default, this action uses the email addresses of users.
39+
Set this input to any non-zero value (e.g. `true`) to derive the GitHub usernames and use them instead.
40+
3641
## Example
3742

3843
This is a typical example for a pull request workflow.
@@ -77,6 +82,7 @@ jobs:
7782
uses: gofunky/[email protected]
7883
with:
7984
distribution: 25
85+
username: true
8086
- name: commit changed files
8187
id: committed
8288
uses: stefanzweifel/[email protected]

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ inputs:
2424
Set this input to any non-zero value (e.g. `true`) to enable full coverage of all recursive files.
2525
required: false
2626
default: ''
27+
username:
28+
description: |
29+
By default, this action uses the email addresses of users.
30+
Set this input to any non-zero value (e.g. `true`) to derive the GitHub usernames and use them instead.
31+
required: false
32+
default: ''
2733
runs:
2834
using: docker
2935
image: Dockerfile

entrypoint.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ if [ -n "$INPUT_GRANULAR" ]; then
1717
echo "Action enabled granular file processing"
1818
fi
1919

20+
identification() {
21+
read -r email
22+
if [ -n "$INPUT_USERNAME" ]; then
23+
if username=$(github-username "$email" --token="$GITHUB_TOKEN");
24+
then
25+
echo "@$username"
26+
else
27+
echo "$email"
28+
fi
29+
else
30+
echo "$email"
31+
fi
32+
}
33+
2034
owners() {
2135
files=""
2236

@@ -29,12 +43,13 @@ owners() {
2943
fi
3044

3145
for file in $files; do
32-
users=$( \
46+
if users=$( \
3347
git fame -eswMC --incl "$file/?[^/]*\.?[^/]*$" \
3448
| tr '/' '|' \
3549
| awk -v "dist=$DISTRIBUTION" -F '|' '(NR>6 && $6>=dist) {gsub(/ /, "", $2); print $2}' \
36-
)
37-
if [ "$?" -eq 0 ]; then
50+
| identification
51+
);
52+
then
3853
if [ -n "$users" ]; then
3954
if [ -n "$INPUT_GRANULAR" ]; then
4055
echo "/$file $users"

0 commit comments

Comments
 (0)