diff --git a/README.md b/README.md index cb9113b389..0e88547e2e 100644 --- a/README.md +++ b/README.md @@ -59,25 +59,34 @@ The official GitHub documentation about Profile READMEs can be found [here](http The Action currently has the following Settings that you can set through the `with` option. -| Option | Description | Default | -| ------------------- | ------------------------------------------------------------ | ----------------------------------------- | -| `COMMIT_MSG` | Sets the message to use for the Commit. | ⚡ Update README with the recent activity | -| `MAX_LINES` | The total amount of lines to display. | 5 | -| `README_FILE` | Path to the MD file you want to push the recent activity to. | ./README.md | -| `COMMENTS_ACTIVITY` | Sets the message to use for the Comments Activity. | 🗣 Commented on {ID} in {REPO} | -| `ISSUE_OPENED` | Sets the message to display when issue is opened | ❗️ Opened issue {ID} in {REPO} | -| `ISSUE_CLOSED` | Sets the message to display when issue is closed | ❗️ Closed issue {ID} in {REPO} | -| `PR_OPENED` | Sets the message to display when pull request is opened | 💪 Opened PR {ID} in {REPO} | -| `PR_CLOSED` | Sets the message to display when pull request is closed | ❌ Closed PR {ID} in {REPO} | -| `PR_MERGED` | Sets the message to display when pull request is merged | 🎉 Merged PR {ID} in {REPO} | -| `DISABLE_COMMENTS` | Whether the comments activity should be hidden | `false` (Boolean) | -| `DISABLE_ISSUES` | Whether the issues events should be hidden | `false` (Boolean) | -| `DISABLE_PR` | Whether the pull request events should be hidden | `false` (Boolean) | - -- {REPO} - Will be changed to the Username/Repository format. -- {ID} - Will be changed to the issue or pull request ID this action belongs to. +| Option | Description | Default | Supported Placeholders | +| ------------------- | ------------------------------------------------------------ | ------------------------------------------- | ------------------------- | +| `COMMIT_MSG` | Sets the message to use for the Commit. | `⚡ Update README with the recent activity` | None | +| `MAX_LINES` | The total amount of lines to display. | `5` | None | +| `README_FILE` | Path to the MD file you want to push the recent activity to. | `./README.md` | None | +| | | | | +| `COMMENTS_ACTIVITY` | Sets the message to use for the Comments Activity. | `🗣 Commented on {ID} in {REPO}` | `{REPO}`, `{ID}`, `{URL}` | +| `ISSUE_OPENED` | Sets the message to display when issue is opened | `❗️ Opened issue {ID} in {REPO}` | `{REPO}`, `{ID}`, `{URL}` | +| `ISSUE_CLOSED` | Sets the message to display when issue is closed | `❗️ Closed issue {ID} in {REPO}` | `{REPO}`, `{ID}`, `{URL}` | +| `PR_OPENED` | Sets the message to display when pull request is opened | `💪 Opened PR {ID} in {REPO}` | `{REPO}`, `{ID}`, `{URL}` | +| `PR_CLOSED` | Sets the message to display when pull request is closed | `❌ Closed PR {ID} in {REPO}` | `{REPO}`, `{ID}`, `{URL}` | +| `PR_MERGED` | Sets the message to display when pull request is merged | `🎉 Merged PR {ID} in {REPO}` | `{REPO}`, `{ID}`, `{URL}` | +| | | | | +| `DISABLE_COMMENTS` | Whether the comments activity should be hidden | `false` (Boolean) | None | +| `DISABLE_ISSUES` | Whether the issues events should be hidden | `false` (Boolean) | None | +| `DISABLE_PR` | Whether the pull request events should be hidden | `false` (Boolean) | None | +| | | | | +| `URL_TEXT` | Change the displayed link-text for `{URL}` | `{REPO}{ID}` | `{REPO}`, `{ID}` | + +### Placeholders + +Following Placeholders are available and can be used in the mentioned options: + +| Placeholder | Description | +| ----------- | --------------------------------------------------------------------------- | +| `{REPO}` | Displays the User and Repository in the format `[:user/:repo](:url)` | +| `{ID}` | Displays the ID of the Issue, PR or Discussion in the format `[#:id](:url)` | +| `{URL}` | Displays whatever was set in `URL_TEXT` in the format `[:url_text](:url)` | ## History @@ -224,3 +233,33 @@ jobs: DISABLE_ISSUES: false DISABLE_PR: false ``` + +### Change `{URL}` Text + +Change the text displayed by `{URL}`. +You can use `{REPO}` and `{ID}` in it. + +Note that the text provided by `URL_TEXT` will be used as displayed text in an embedded link. +For example will `{REPO}{ID}` become `[{REPO}{ID}](:url)`. + +```yaml +name: Update README + +on: + schedule: + - cron: "*/30 * * * *" + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + name: Update Profile README + + steps: + - uses: actions/checkout@v2 + - uses: Readme-Workflows/recent-activity@main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + URL_TEXT: "`{REPO}{ID}`" # Turns into [`{REPO}{ID}`](:url) +``` diff --git a/action.yml b/action.yml index 5b9160229f..3a47958c96 100644 --- a/action.yml +++ b/action.yml @@ -33,6 +33,11 @@ inputs: default: false required: false + URL_TEXT: + description: "Format in which {URL} will be replaced" + default: "{REPO}{ID}" + required: false + # COMMENTS COMMENTS_ACTIVITY: description: "How the comments activity should be printed." diff --git a/dist/index.js b/dist/index.js index 735ebc67e9..896deb7882 100644 --- a/dist/index.js +++ b/dist/index.js @@ -15253,6 +15253,7 @@ const PR_MERGED = core.getInput("PR_MERGED"); const DISABLE_COMMENTS = core.getInput("DISABLE_COMMENTS"); const DISABLE_ISSUES = core.getInput("DISABLE_ISSUES"); const DISABLE_PR = core.getInput("DISABLE_PR"); +const URL_TEXT = core.getInput("URL_TEXT"); /** * Returns the sentence case representation @@ -15272,6 +15273,22 @@ const urlPrefix = "https://github.com"; * @returns {String} */ +const makeCustomUrl = (item) => { + return Object.hasOwnProperty.call(item.payload, "issue") + ? `[` + + URL_TEXT.replace(/{ID}/g, `#${item.payload.issue.number}`).replace( + /{REPO}/g, + item.repo.name + ) + + `](${urlPrefix}/${item.repo.name}/issues/${item.payload.issue.number})` + : `[` + + URL_TEXT.replace( + /{ID}/g, + `#${item.payload.pull_request.number}` + ).replace(/{REPO}/g, item.repo.name) + + `](${urlPrefix}/${item.repo.name}/pull/${item.payload.pull_request.number})`; +}; + const toUrlFormat = (item) => { if (typeof item === "object") { return Object.hasOwnProperty.call(item.payload, "issue") @@ -15330,10 +15347,9 @@ const serializers = {}; if (DISABLE_COMMENTS === "false") { serializers.IssueCommentEvent = (item) => { - return COMMENTS_ACTIVITY.replace(/{ID}/g, toUrlFormat(item)).replace( - /{REPO}/g, - toUrlFormat(item.repo.name) - ); + return COMMENTS_ACTIVITY.replace(/{ID}/g, toUrlFormat(item)) + .replace(/{REPO}/g, toUrlFormat(item.repo.name)) + .replace(/{URL}/g, makeCustomUrl(item)); }; // return `🗣 Commented on ${toUrlFormat(item)} in ${toUrlFormat( // item.repo.name @@ -15342,15 +15358,13 @@ if (DISABLE_COMMENTS === "false") { if (DISABLE_ISSUES === "false") { serializers.IssuesEvent = (item) => { if (item.payload.action === "opened") { - return ISSUE_OPENED.replace(/{ID}/g, toUrlFormat(item)).replace( - /{REPO}/g, - toUrlFormat(item.repo.name) - ); + return ISSUE_OPENED.replace(/{ID}/g, toUrlFormat(item)) + .replace(/{REPO}/g, toUrlFormat(item.repo.name)) + .replace(/{URL}/g, makeCustomUrl(item)); } else if (item.payload.action === "closed") { - return ISSUE_CLOSED.replace(/{ID}/g, toUrlFormat(item)).replace( - /{REPO}/g, - toUrlFormat(item.repo.name) - ); + return ISSUE_CLOSED.replace(/{ID}/g, toUrlFormat(item)) + .replace(/{REPO}/g, toUrlFormat(item.repo.name)) + .replace(/{URL}/g, makeCustomUrl(item)); } else { return `❗️ ${capitalize(item.payload.action)} issue ${toUrlFormat( item @@ -15361,20 +15375,17 @@ if (DISABLE_ISSUES === "false") { if (DISABLE_PR === "false") { serializers.PullRequestEvent = (item) => { if (item.payload.action === "opened") { - return PR_OPENED.replace(/{ID}/g, toUrlFormat(item)).replace( - /{REPO}/g, - toUrlFormat(item.repo.name) - ); + return PR_OPENED.replace(/{ID}/g, toUrlFormat(item)) + .replace(/{REPO}/g, toUrlFormat(item.repo.name)) + .replace(/{URL}/g, makeCustomUrl(item)); } else if (item.payload.action === "closed") { - return PR_CLOSED.replace(/{ID}/g, toUrlFormat(item)).replace( - /{REPO}/g, - toUrlFormat(item.repo.name) - ); + return PR_CLOSED.replace(/{ID}/g, toUrlFormat(item)) + .replace(/{REPO}/g, toUrlFormat(item.repo.name)) + .replace(/{URL}/g, makeCustomUrl(item)); } else if (item.payload.pull_request.merged) { - return PR_MERGED.replace(/{ID}/g, toUrlFormat(item)).replace( - /{REPO}/g, - toUrlFormat(item.repo.name) - ); + return PR_MERGED.replace(/{ID}/g, toUrlFormat(item)) + .replace(/{REPO}/g, toUrlFormat(item.repo.name)) + .replace(/{URL}/g, makeCustomUrl(item)); } // if (item.payload.action === "opened") { diff --git a/index.js b/index.js index 535e908a14..22e083058d 100644 --- a/index.js +++ b/index.js @@ -21,6 +21,7 @@ const PR_MERGED = core.getInput("PR_MERGED"); const DISABLE_COMMENTS = core.getInput("DISABLE_COMMENTS"); const DISABLE_ISSUES = core.getInput("DISABLE_ISSUES"); const DISABLE_PR = core.getInput("DISABLE_PR"); +const URL_TEXT = core.getInput("URL_TEXT"); /** * Returns the sentence case representation @@ -40,6 +41,22 @@ const urlPrefix = "https://github.com"; * @returns {String} */ +const makeCustomUrl = (item) => { + return Object.hasOwnProperty.call(item.payload, "issue") + ? `[` + + URL_TEXT.replace(/{ID}/g, `#${item.payload.issue.number}`).replace( + /{REPO}/g, + item.repo.name + ) + + `](${urlPrefix}/${item.repo.name}/issues/${item.payload.issue.number})` + : `[` + + URL_TEXT.replace( + /{ID}/g, + `#${item.payload.pull_request.number}` + ).replace(/{REPO}/g, item.repo.name) + + `](${urlPrefix}/${item.repo.name}/pull/${item.payload.pull_request.number})`; +}; + const toUrlFormat = (item) => { if (typeof item === "object") { return Object.hasOwnProperty.call(item.payload, "issue") @@ -98,10 +115,9 @@ const serializers = {}; if (DISABLE_COMMENTS === "false") { serializers.IssueCommentEvent = (item) => { - return COMMENTS_ACTIVITY.replace(/{ID}/g, toUrlFormat(item)).replace( - /{REPO}/g, - toUrlFormat(item.repo.name) - ); + return COMMENTS_ACTIVITY.replace(/{ID}/g, toUrlFormat(item)) + .replace(/{REPO}/g, toUrlFormat(item.repo.name)) + .replace(/{URL}/g, makeCustomUrl(item)); }; // return `🗣 Commented on ${toUrlFormat(item)} in ${toUrlFormat( // item.repo.name @@ -110,15 +126,13 @@ if (DISABLE_COMMENTS === "false") { if (DISABLE_ISSUES === "false") { serializers.IssuesEvent = (item) => { if (item.payload.action === "opened") { - return ISSUE_OPENED.replace(/{ID}/g, toUrlFormat(item)).replace( - /{REPO}/g, - toUrlFormat(item.repo.name) - ); + return ISSUE_OPENED.replace(/{ID}/g, toUrlFormat(item)) + .replace(/{REPO}/g, toUrlFormat(item.repo.name)) + .replace(/{URL}/g, makeCustomUrl(item)); } else if (item.payload.action === "closed") { - return ISSUE_CLOSED.replace(/{ID}/g, toUrlFormat(item)).replace( - /{REPO}/g, - toUrlFormat(item.repo.name) - ); + return ISSUE_CLOSED.replace(/{ID}/g, toUrlFormat(item)) + .replace(/{REPO}/g, toUrlFormat(item.repo.name)) + .replace(/{URL}/g, makeCustomUrl(item)); } else { return `❗️ ${capitalize(item.payload.action)} issue ${toUrlFormat( item @@ -129,20 +143,17 @@ if (DISABLE_ISSUES === "false") { if (DISABLE_PR === "false") { serializers.PullRequestEvent = (item) => { if (item.payload.action === "opened") { - return PR_OPENED.replace(/{ID}/g, toUrlFormat(item)).replace( - /{REPO}/g, - toUrlFormat(item.repo.name) - ); + return PR_OPENED.replace(/{ID}/g, toUrlFormat(item)) + .replace(/{REPO}/g, toUrlFormat(item.repo.name)) + .replace(/{URL}/g, makeCustomUrl(item)); } else if (item.payload.action === "closed") { - return PR_CLOSED.replace(/{ID}/g, toUrlFormat(item)).replace( - /{REPO}/g, - toUrlFormat(item.repo.name) - ); + return PR_CLOSED.replace(/{ID}/g, toUrlFormat(item)) + .replace(/{REPO}/g, toUrlFormat(item.repo.name)) + .replace(/{URL}/g, makeCustomUrl(item)); } else if (item.payload.pull_request.merged) { - return PR_MERGED.replace(/{ID}/g, toUrlFormat(item)).replace( - /{REPO}/g, - toUrlFormat(item.repo.name) - ); + return PR_MERGED.replace(/{ID}/g, toUrlFormat(item)) + .replace(/{REPO}/g, toUrlFormat(item.repo.name)) + .replace(/{URL}/g, makeCustomUrl(item)); } // if (item.payload.action === "opened") {