Skip to content

Updated to get git username #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/event-logger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ jobs:
run: |
echo $COMMITS > commits.json
cat commits.json # debugging
GIT_USERNAME=$(jq -r '.[0].commit.author.name' commits.json) # Extract Git username
echo "Git Username: $GIT_USERNAME"
pipenv run gitcommitlogger -r $(echo $REPOSITORY_URL) -t pull_request_merged -d $(echo $PR_CLOSED_AT) -un $(echo $GITHUB_LOGIN) -i commits.json -o commit_stats.csv -u $(echo $COMMIT_LOG_API) -v
echo "GIT_USERNAME=$GIT_USERNAME" >> $GITHUB_ENV # Pass it to the next steps
- name: Log pull request closed without merge
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == false
run: |
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/hook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ jobs:
node-version: "14"

- name: Install dependencies
run: npm install -g nodemailer
run: npm install nodemailer

- name: Set Git Username
run: echo "GIT_USERNAME=$(git config user.name)" >> $GITHUB_ENV

- name: Send email notification
env:
Expand All @@ -31,9 +34,11 @@ jobs:
EVENT_TYPE: ${{ github.event_name }}
EMAIL: ${{ secrets.EMAIL }}
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
GIT_USERNAME: ${{ env.GIT_USERNAME }}
run: |
node -e "
const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
Expand All @@ -46,16 +51,18 @@ jobs:
from: process.env.EMAIL,
to: process.env.EMAIL,
subject: 'GitHub Event Notification',
text: \`Event Type: ${{ github.event_name }}\n
GitHub Event: ${{ env.GITHUB_EVENT }}\n
GitHub Actor: ${{ env.GITHUB_ACTOR }}\n
GitHub User: ${{ env.GITHUB_USER }}\`
text: \`Event Type: \${process.env.EVENT_TYPE}\n
GitHub Event: \${process.env.GITHUB_EVENT}\n
GitHub Actor: \${process.env.GITHUB_ACTOR}\n
GitHub User: \${process.env.GITHUB_USER}\n
Git User (Git Username from commit): \${process.env.GIT_USERNAME}\`
};

transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
console.log('Error:', error);
} else {
console.log('Email sent:', info.response);
}
console.log('Email sent: ' + info.response);
});
"