Skip to content

Commit

Permalink
Add custom committer name and email
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Larwig <jan@larwig.com>
  • Loading branch information
Lorenzo0111 and tuunit committed May 31, 2023
1 parent bfb65a4 commit 21d9a86
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
17 changes: 8 additions & 9 deletions README.md
Expand Up @@ -16,12 +16,10 @@ Updates `README.md` with the recent GitHub activity of a user.

```yml
name: Update README

on:
schedule:
- cron: "*/30 * * * *"
workflow_dispatch:

jobs:
build:
name: Update this repo's README with recent activity
Expand Down Expand Up @@ -51,20 +49,20 @@ You can find an example [here](https://github.com/jamesgeorge007/jamesgeorge007/

Use the following `input params` to customize it for your use case:-

| Input Param | Default Value | Description |
| ------------- | -------------------------------------------- | --------------------------------------------------------- |
| `COMMIT_MSG` | :zap: Update README with the recent activity | Commit message used while committing to the repo |
| `MAX_LINES` | 5 | The maximum number of lines populated in your readme file |
| `TARGET_FILE` | README.md | The file to insert recent activity into |
| Input Param | Default Value | Description |
| -------------- | ----------------------------------------------------- | --------------------------------------------------------- |
| `COMMIT_NAME` | github-actions[bot] | Name of the committer |
| `COMMIT_EMAIL` | 41898282+github-actions[bot]@users.noreply.github.com | Email of the committer |
| `COMMIT_MSG` | :zap: Update README with the recent activity | Commit message used while committing to the repo |
| `MAX_LINES` | 5 | The maximum number of lines populated in your readme file |
| `TARGET_FILE` | README.md | The file to insert recent activity into |

```yml
name: Update README

on:
schedule:
- cron: "*/30 * * * *"
workflow_dispatch:

jobs:
build:
name: Update this repo's README with recent activity
Expand All @@ -80,6 +78,7 @@ jobs:
with:
COMMIT_MSG: "Specify a custom commit message"
MAX_LINES: 10
COMMIT_NAME: GitHub Activity Readme
```

_Inspired by [JasonEtco/activity-box](https://github.com/JasonEtco/activity-box)_
10 changes: 9 additions & 1 deletion action.yml
Expand Up @@ -4,9 +4,17 @@ author: jamesgeorge007

inputs:
GH_USERNAME:
description: 'Your GitHub username'
description: "Your GitHub username"
default: ${{ github.repository_owner }}
required: false
COMMIT_NAME:
description: "Name of the committer"
default: "github-actions[bot]"
required: false
COMMIT_EMAIL:
description: "Email of the committer"
default: "41898282+github-actions[bot]@users.noreply.github.com"
required: false
COMMIT_MSG:
description: "Commit message used while committing to the repo"
default: ":zap: Update README with the recent activity"
Expand Down
13 changes: 5 additions & 8 deletions dist/index.js
Expand Up @@ -1789,9 +1789,11 @@ const { Toolkit } = __webpack_require__(461);

// Get config
const GH_USERNAME = core.getInput("GH_USERNAME");
const COMMIT_NAME = core.getInput("COMMIT_NAME");
const COMMIT_EMAIL = core.getInput("COMMIT_EMAIL");
const COMMIT_MSG = core.getInput("COMMIT_MSG");
const MAX_LINES = core.getInput("MAX_LINES");
const TARGET_FILE = core.getInput("TARGET_FILE") || "README.md";
const TARGET_FILE = core.getInput("TARGET_FILE");

/**
* Returns the sentence case representation
Expand Down Expand Up @@ -1853,13 +1855,8 @@ const exec = (cmd, args = []) =>
*/

const commitFile = async () => {
await exec("git", [
"config",
"--global",
"user.email",
"41898282+github-actions[bot]@users.noreply.github.com",
]);
await exec("git", ["config", "--global", "user.name", "readme-bot"]);
await exec("git", ["config", "--global", "user.email", COMMIT_EMAIL]);
await exec("git", ["config", "--global", "user.name", COMMIT_NAME]);
await exec("git", ["add", TARGET_FILE]);
await exec("git", ["commit", "-m", COMMIT_MSG]);
await exec("git", ["push"]);
Expand Down
11 changes: 4 additions & 7 deletions index.js
Expand Up @@ -6,6 +6,8 @@ const { Toolkit } = require("actions-toolkit");

// Get config
const GH_USERNAME = core.getInput("GH_USERNAME");
const COMMIT_NAME = core.getInput("COMMIT_NAME");
const COMMIT_EMAIL = core.getInput("COMMIT_EMAIL");
const COMMIT_MSG = core.getInput("COMMIT_MSG");
const MAX_LINES = core.getInput("MAX_LINES");
const TARGET_FILE = core.getInput("TARGET_FILE");
Expand Down Expand Up @@ -70,13 +72,8 @@ const exec = (cmd, args = []) =>
*/

const commitFile = async () => {
await exec("git", [
"config",
"--global",
"user.email",
"41898282+github-actions[bot]@users.noreply.github.com",
]);
await exec("git", ["config", "--global", "user.name", "readme-bot"]);
await exec("git", ["config", "--global", "user.email", COMMIT_EMAIL]);
await exec("git", ["config", "--global", "user.name", COMMIT_NAME]);
await exec("git", ["add", TARGET_FILE]);
await exec("git", ["commit", "-m", COMMIT_MSG]);
await exec("git", ["push"]);
Expand Down

0 comments on commit 21d9a86

Please sign in to comment.