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

Feature: Split PR & issues into separate events #272

Merged
merged 10 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ Events we support:
- IssueCommentEvent - You commented on a issue
- IssuesEvent - You opened a issue
- MemberEvent - You joined a org/repo as a member
- PullRequestEvent - You opened a pr.
- PullRequestOpenEvent - You opened a pr.
- PullRequestMergeEvent - You merged a pr.
- PullRequestCloseEvent - You closed a pr.
- PullRequestReviewCommentEvent - You commented on a pr review
- PullRequestReviewEvent - You reviewed a pr
- ReleaseEvent - You released a new version
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,22 @@ The setting can be used in two ways:
##### Supported Events
The following list of events is supported for the [`disabled_events`](#disabled_events) and [`whitelisted_events`](#whitelisted_events) setting.

| Type: | Disabled Actions: |
| ------------- | ------------------------------------------------- |
| `comments` | Commenting on Issues |
| `create_repo` | Creating a new Repository |
| `fork` | Forking a Repository |
| `issues` | Opening or closing Issues |
| `member` | Getting added as a Collaborator/Member |
| `pr` | Opening, closing or Merging a Pull request |
| `push` | All commits performed |
| `release` | Publishing a new Release |
| `review` | Approving or requesting Changes in a Pull request |
| `star` | Starring a Repository |
| `wiki` | Creating a new Wiki page |
| Type: | Disabled Actions: |
| -------------- | ------------------------------------------------- |
| `comments` | Commenting on Issues |
| `create_repo` | Creating a new Repository |
| `fork` | Forking a Repository |
| `issues_open` | Opening Issues |
| `issues_close` | Closing Issues |
| `member` | Getting added as a Collaborator/Member |
| `pr_open` | Opening a Pull request |
| `pr_merge` | Merging a Pull request |
| `pr_close` | Closing a Pull request |
| `push` | All commits performed |
| `release` | Publishing a new Release |
| `review` | Approving or requesting Changes in a Pull request |
| `star` | Starring a Repository |
| `wiki` | Creating a new Wiki page |

#### `commit_name`
> **Default:** `readme-bot`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "activity-readme",
"version": "2.4.1",
"version": "2.5.0",
"description": "Updates README with the recent GitHub activity of a user. This project is a fork of https://github.com/jamesgeorge007/github-activity-readme",
"main": "src/index.js",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const defaultVals = {
text: "Last Updated: {DATE}",
format: "dddd, mmmm dS, yyyy, h:MM:ss TT",
},
ignored_repos:[],
ignored_repos: [],
comments: "💬 Commented on {ID} in {REPO}",
push: "⬆️ Pushed {AMOUNT} commit(s) to {REPO}",
issue_opened: "❗️ Opened issue {ID} in {REPO}",
Expand Down
7 changes: 5 additions & 2 deletions src/eventList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ module.exports = [
"push",
"create_repo",
"fork",
"issues",
"issues_open",
"issues_close",
"member",
"pr",
"pr_open",
"pr_merge",
"pr_close",
"release",
"review",
"star",
Expand Down
16 changes: 16 additions & 0 deletions src/events/IssuesCloseEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { issue_closed } = require("../config");
const makeCustomUrl = require("../functions/makeCustomUrl");
const toUrlFormat = require("../functions/toUrlFormat");

const IssuesEvent = (item) => {
if (item.payload.action === "closed") {
return issue_closed
.replace(/{ID}/g, toUrlFormat(item, "issue_close"))
.replace(/{REPO}/g, toUrlFormat(item.repo.name, "issue_close"))
.replace(/{URL}/g, makeCustomUrl(item, "issue_close"));
} else {
return "";
}
};

module.exports = IssuesEvent;
9 changes: 1 addition & 8 deletions src/events/IssuesEvent.js → src/events/IssuesOpenEvent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { issue_opened, issue_closed } = require("../config");
const { issue_opened } = require("../config");
const makeCustomUrl = require("../functions/makeCustomUrl");
const toUrlFormat = require("../functions/toUrlFormat");

Expand All @@ -8,13 +8,6 @@ const IssuesEvent = (item) => {
.replace(/{ID}/g, toUrlFormat(item, "issue_open"))
.replace(/{REPO}/g, toUrlFormat(item.repo.name, "issue_open"))
.replace(/{URL}/g, makeCustomUrl(item, "issue_open"));
} else if (item.payload.action === "closed") {
return issue_closed
.replace(/{ID}/g, toUrlFormat(item, "issue_close"))
.replace(/{REPO}/g, toUrlFormat(item.repo.name, "issue_close"))
.replace(/{URL}/g, makeCustomUrl(item, "issue_close"));
} else {
return "";
}
};

Expand Down
15 changes: 15 additions & 0 deletions src/events/PullRequestCloseEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { pr_closed } = require("../config");
const makeCustomUrl = require("../functions/makeCustomUrl");
const toUrlFormat = require("../functions/toUrlFormat");

const PullRequestCloseEvent = (item) => {
if (item.payload.action === "closed" && !item.payload.pull_request.merged) {
return pr_closed
.replace(/{ID}/g, toUrlFormat(item, "pr_close"))
.replace(/{REPO}/g, toUrlFormat(item.repo.name, "pr_close"))
.replace(/{URL}/g, makeCustomUrl(item, "pr_close"));
} else {
return "";
}
};
module.exports = PullRequestCloseEvent;
29 changes: 0 additions & 29 deletions src/events/PullRequestEvent.js

This file was deleted.

16 changes: 16 additions & 0 deletions src/events/PullRequestMergeEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { pr_merged } = require("../config");
const makeCustomUrl = require("../functions/makeCustomUrl");
const toUrlFormat = require("../functions/toUrlFormat");

const PullRequestMergeEvent = (item) => {
if (item.payload.action === "merge") {
return pr_merged
.replace(/{ID}/g, toUrlFormat(item, "pr_merge"))
.replace(/{REPO}/g, toUrlFormat(item.repo.name, "pr_merge"))
.replace(/{URL}/g, makeCustomUrl(item, "pr_merge"));
} else {
return "";
}
};

module.exports = PullRequestMergeEvent;
16 changes: 16 additions & 0 deletions src/events/PullRequestOpenEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { pr_opened } = require("../config");
const makeCustomUrl = require("../functions/makeCustomUrl");
const toUrlFormat = require("../functions/toUrlFormat");

const PullRequestOpenEvent = (item) => {
if (item.payload.action === "opened") {
return pr_opened
.replace(/{ID}/g, toUrlFormat(item, "pr_open"))
.replace(/{REPO}/g, toUrlFormat(item.repo.name, "pr_open"))
.replace(/{URL}/g, makeCustomUrl(item, "pr_open"));
} else {
return "";
}
};

module.exports = PullRequestOpenEvent;
27 changes: 21 additions & 6 deletions src/serializers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ const IssueCommentEvent = require("./events/IssueCommentEvent");
const CommitCommentEvent = require("./events/CommitCommentEvent");
const PullRequestReviewCommentEvent = require("./events/PullRequestReviewCommentEvent");
const PushEvent = require("./events/PushEvent");
const IssuesEvent = require("./events/IssuesEvent");
const PullRequestEvent = require("./events/PullRequestEvent");
const IssuesOpenEvent = require("./events/IssuesOpenEvent");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the problem lies. GitHub API does not provide a type of the value "IssuesOpenEvent" or the other new names that you have made. Due to this change, while testing I see that none of the issue and pull request-related events are shown in the profile.
You can checkout https://docs.github.com/en/developers/webhooks-and-events/github-event-types for the docs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to modify the functions/filterContent.js file to use the respective serializers for their respective events

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, thanks for the info.
Rn I don't have the time, so I can close the PR until I can look into this if you want me to?

Copy link
Member

@PuneetGopinath PuneetGopinath Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to close the pr, let it be open. Whenever free you can look into the issue, that's not an problem.
We appreciate your efforts to contribute to Readme-Workflows!

const IssuesCloseEvent = require("./events/IssuesCloseEvent");
const PullRequestOpenEvent = require("./events/PullRequestOpenEvent");
const PullRequestMergeEvent = require("./events/PullRequestMergeEvent");
const PullRequestCloseEvent = require("./events/PullRequestCloseEvent");
const CreateEvent = require("./events/CreateEvent");
const ForkEvent = require("./events/ForkEvent");
const GollumEvent = require("./events/GollumEvent");
Expand All @@ -32,12 +35,24 @@ if (!disabled_events.includes("push")) {
serializers.PushEvent = PushEvent;
}

if (!disabled_events.includes("issues")) {
serializers.IssuesEvent = IssuesEvent;
if (!disabled_events.includes("issues_open")) {
serializers.IssuesOpenEvent = IssuesOpenEvent;
}

if (!disabled_events.includes("pr")) {
serializers.PullRequestEvent = PullRequestEvent;
if (!disabled_events.includes("issues_close")) {
serializers.IssuesCloseEvent = IssuesCloseEvent;
}

if (!disabled_events.includes("pr_open")) {
serializers.PullRequestOpenEvent = PullRequestOpenEvent;
}

if (!disabled_events.includes("pr_merge")) {
serializers.PullRequestMergeEvent = PullRequestMergeEvent;
}

if (!disabled_events.includes("pr_close")) {
serializers.PullRequestCloseEvent = PullRequestCloseEvent;
}

if (!disabled_events.includes("create_repo")) {
Expand Down