Skip to content
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

Added URL_FORMAT parameter #15

Merged
merged 6 commits into from
May 9, 2021
Merged
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
77 changes: 58 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
```
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
59 changes: 35 additions & 24 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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") {
Expand Down
59 changes: 35 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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") {
Expand Down