Skip to content

Commit 7bb79f7

Browse files
committed
Merge branch 'main' into main-modal-doc
2 parents 48620bb + 7a7cca0 commit 7bb79f7

29 files changed

+1329
-35
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ The GitHub Rocket.Chat App provides a seamless integration between GitHub and Ro
5656
<li><strong>Get Issues of a Repository →</strong> <code>/github Username/RepositoryName issues</code></li>
5757
<li><strong>Get Contributors of a Repository →</strong> <code>/github Username/RepositoryName contributors</code></li>
5858
<li><strong>Get Recent Pull Request of a Repository →</strong> <code>/github Username/RepositoryName pulls</code></li>
59+
<li>Add a new repository for pull request review reminders -> /github reminder create</li>
60+
<li>Get a list of repositories for which you've set up pull request review reminders -> /github reminder list</li>
5961
</ul>
6062

6163

github/GithubApp.ts

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import {
22
IAppAccessors,
33
IAppInstallationContext,
44
IConfigurationExtend,
5+
IConfigurationModify,
56
IHttp,
67
ILogger,
8+
IMessageBuilder,
9+
IMessageExtender,
710
IModify,
811
IPersistence,
912
IRead,
@@ -12,6 +15,7 @@ import { App } from "@rocket.chat/apps-engine/definition/App";
1215
import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata";
1316
import { GithubCommand } from "./commands/GithubCommand";
1417
import {
18+
ButtonStyle,
1519
IUIKitResponse,
1620
UIKitBlockInteractionContext,
1721
UIKitViewCloseInteractionContext,
@@ -27,30 +31,74 @@ import {
2731
IOAuth2ClientOptions,
2832
} from "@rocket.chat/apps-engine/definition/oauth2/IOAuth2";
2933
import { createOAuth2Client } from "@rocket.chat/apps-engine/definition/oauth2/OAuth2";
30-
import { createSectionBlock } from "./lib/blocks";
3134
import {
3235
sendDirectMessage,
3336
sendDirectMessageOnInstall,
37+
sendMessage,
3438
sendNotification,
3539
} from "./lib/message";
36-
import { OAuth2Client } from "@rocket.chat/apps-engine/server/oauth2/OAuth2Client";
3740
import { deleteOathToken } from "./processors/deleteOAthToken";
3841
import { ProcessorsEnum } from "./enum/Processors";
3942
import {
4043
ApiSecurity,
4144
ApiVisibility,
4245
} from "@rocket.chat/apps-engine/definition/api";
4346
import { githubWebHooks } from "./endpoints/githubEndpoints";
44-
import { IJobContext } from "@rocket.chat/apps-engine/definition/scheduler";
47+
import { IJobContext, StartupType } from "@rocket.chat/apps-engine/definition/scheduler";
4548
import { IRoom } from "@rocket.chat/apps-engine/definition/rooms";
4649
import { clearInteractionRoomData, getInteractionRoomData } from "./persistance/roomInteraction";
4750
import { GHCommand } from "./commands/GhCommand";
51+
import { IPreMessageSentExtend, IMessage,IPreMessageSentModify, IPostMessageSent } from "@rocket.chat/apps-engine/definition/messages";
52+
import { handleGitHubCodeSegmentLink } from "./handlers/GitHubCodeSegmentHandler";
53+
import { isGithubLink, hasGitHubCodeSegmentLink, hasGithubPRLink } from "./helpers/checkLinks";
54+
import { SendReminder } from "./handlers/SendReminder";
55+
import { AppSettings, settings } from "./settings/settings";
56+
import { ISetting } from "@rocket.chat/apps-engine/definition/settings";import { handleGithubPRLink } from "./handlers/GithubPRlinkHandler";
4857

49-
export class GithubApp extends App {
58+
export class GithubApp extends App implements IPreMessageSentExtend,IPostMessageSent{
5059
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
5160
super(info, logger, accessors);
5261
}
5362

63+
async checkPostMessageSent?(message: IMessage, read: IRead, http: IHttp): Promise<boolean> {
64+
if (await hasGithubPRLink(message)){
65+
return true
66+
}
67+
return false;
68+
}
69+
70+
async executePostMessageSent(message: IMessage, read: IRead, http: IHttp, persistence: IPersistence, modify: IModify): Promise<void> {
71+
72+
await handleGithubPRLink(message,read,http,persistence,modify)
73+
74+
}
75+
76+
public async checkPreMessageSentExtend(
77+
message: IMessage,
78+
read: IRead,
79+
http: IHttp
80+
): Promise<boolean> {
81+
if (await isGithubLink(message)) {
82+
return true;
83+
}
84+
return false;
85+
}
86+
87+
public async executePreMessageSentExtend(
88+
message: IMessage,
89+
extend: IMessageExtender,
90+
read: IRead,
91+
http: IHttp,
92+
persistence: IPersistence
93+
): Promise<IMessage> {
94+
95+
if (await hasGitHubCodeSegmentLink(message)) {
96+
await handleGitHubCodeSegmentLink(message, read, http, message.sender, message.room, extend);
97+
}
98+
99+
return extend.getMessage();
100+
}
101+
54102
public async authorizationCallback(
55103
token: IAuthData,
56104
user: IUser,
@@ -164,11 +212,17 @@ export class GithubApp extends App {
164212
): Promise<void> {
165213
const gitHubCommand: GithubCommand = new GithubCommand(this);
166214
const ghCommand: GHCommand = new GHCommand(this);
215+
167216
await Promise.all([
168217
configuration.slashCommands.provideSlashCommand(gitHubCommand),
169218
configuration.slashCommands.provideSlashCommand(ghCommand),
170219
this.getOauth2ClientInstance().setup(configuration),
171220
]);
221+
await Promise.all(
222+
settings.map((setting) =>
223+
configuration.settings.provideSetting(setting)
224+
)
225+
);
172226
configuration.scheduler.registerProcessors([
173227
{
174228
id: ProcessorsEnum.REMOVE_GITHUB_LOGIN,
@@ -195,6 +249,17 @@ export class GithubApp extends App {
195249
}
196250
},
197251
},
252+
{
253+
id:ProcessorsEnum.PR_REMINDER,
254+
processor:async(jobData,read,modify,http,persis) =>{
255+
await SendReminder(jobData,read,modify,http,persis,this)
256+
},
257+
startupSetting:{
258+
type:StartupType.RECURRING,
259+
interval:"0 9 * * *"
260+
}
261+
262+
}
198263
]);
199264
configuration.api.provideApi({
200265
visibility: ApiVisibility.PUBLIC,
@@ -212,4 +277,13 @@ export class GithubApp extends App {
212277
const user = context.user;
213278
await sendDirectMessageOnInstall(read, modify, user, persistence);
214279
}
280+
281+
public async onSettingUpdated(setting: ISetting, configurationModify: IConfigurationModify, read: IRead, http: IHttp): Promise<void> {
282+
const interval:string = await this.getAccessors().environmentReader.getSettings().getValueById(AppSettings.ReminderCORNjobString);
283+
await configurationModify.scheduler.cancelJob(ProcessorsEnum.PR_REMINDER);
284+
await configurationModify.scheduler.scheduleRecurring({
285+
id:ProcessorsEnum.PR_REMINDER,
286+
interval:interval,
287+
})
288+
}
215289
}

github/app.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
"nameSlug": "github",
1313
"classFile": "GithubApp.ts",
1414
"description": "The ultimate app extending Rocket.Chat for all developers collaborating on Github",
15-
"implements": []
15+
"implements": [
16+
"IPreMessageSentExtend",
17+
"IPostMessageSent"
18+
]
1619
}

github/commands/GithubCommand.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,4 @@ export class GithubCommand implements ISlashCommand {
5050
);
5151

5252
commandUtility.resolveCommand();
53-
}}
54-
53+
}}

github/definitions/PRdetails.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface IPRdetail{
2+
title: string;
3+
number:string;
4+
url: string;
5+
id: string;
6+
createdAt: Date;
7+
ageInDays?:number;
8+
author: { avatar: string; username: string; };repo:string;
9+
}

github/definitions/Reminder.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface IReminder {
2+
userid:string,
3+
username:string,
4+
repos: string[];
5+
unsubscribedPR:{repo:string,prnum:number[]}[]
6+
}

github/endpoints/githubEndpoints.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ export class githubWebHooks extends ApiEndpoint {
5656
messageText = `*New Commits to* *[${payload.repository.full_name}](${payload.repository.html_url}) by ${payload.pusher.name}*`;
5757
} else if (event == "pull_request") {
5858
if(payload.action == "opened"){
59-
messageText = `*[New Pull Request](${payload.pull_request.html_url})* *|* *#${payload.pull_request.number} ${payload.pull_request.title}* by *[${payload.user.login}](${payload.user.html_url})* *|* *[${payload.repository.full_name}]*`;
59+
messageText = `*[New Pull Request](${payload.pull_request.html_url})* *|* *#${payload.pull_request.number} ${payload.pull_request.title}* by *[${payload.pull_request.user.login}](${payload.pull_request.user.html_url})* *|* *[${payload.repository.full_name}]*`;
6060
}else if(payload.action == "closed" && payload.pull_request.merged ){
61-
messageText = `*[Merged Pull Request](${payload.pull_request.html_url})* *|* *#${payload.pull_request.number} ${payload.pull_request.title}* by *[${payload.user.login}](${payload.user.html_url})* *|* *[${payload.repository.full_name}]*`;
61+
messageText = `*[Merged Pull Request](${payload.pull_request.html_url})* *|* *#${payload.pull_request.number} ${payload.pull_request.title}* by *[${payload.pull_request.user.login}](${payload.pull_request.user.html_url})* *|* *[${payload.repository.full_name}]*`;
6262
}else if(payload.action == "closed" && !payload.pull_request.merged){
63-
messageText = `*[Closed Pull Request](${payload.pull_request.html_url})* *|* *#${payload.pull_request.number} ${payload.pull_request.title}* by *[${payload.user.login}](${payload.user.html_url})* *|* *[${payload.repository.full_name}]*`;
63+
messageText = `*[Closed Pull Request](${payload.pull_request.html_url})* *|* *#${payload.pull_request.number} ${payload.pull_request.title}* by *[${payload.pull_request.user.login}](${payload.pull_request.user.html_url})* *|* *[${payload.repository.full_name}]*`;
6464
}else if(payload.action =="reopened"){
65-
messageText = `*[ReOpened Pull Request](${payload.pull_request.html_url})* *|* *#${payload.pull_request.number} ${payload.pull_request.title}* by *[${payload.user.login}](${payload.user.html_url})* *|* *[${payload.repository.full_name}]*`;
65+
messageText = `*[ReOpened Pull Request](${payload.pull_request.html_url})* *|* *#${payload.pull_request.number} ${payload.pull_request.title}* by *[${payload.pull_request.user.login}](${payload.pull_request.user.html_url})* *|* *[${payload.repository.full_name}]*`;
6666
}else{
6767
return this.success();
6868
}
@@ -105,4 +105,4 @@ export class githubWebHooks extends ApiEndpoint {
105105

106106
return this.success();
107107
}
108-
}
108+
}

github/enum/App.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export enum AppEnum {
33
USERNAME_ALIAS = 'GitHub',
44
EMOJI_AVATAR = '',
55
USER_MESSAGED_BOT = 'You have messaged the bot user. This has no effect.',
6+
APP_ID='826f0d95-9e25-48a6-a781-a32f147230a5'
67
}

github/enum/GitHubURL.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum GitHubURLEnum {
2+
PREFIX = "blob/",
3+
HOST = "github.com",
4+
RAW_HOST = "raw.githubusercontent.com",
5+
}

github/enum/Modals.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export enum ModalsEnum {
3434
PULL_VIEW_LABEL = 'Pull Request',
3535
MERGE_PULL_REQUEST_ACTION = 'merge-pull-request',
3636
MERGE_PULL_REQUEST_LABEL = 'Merge',
37+
APPROVE_PULL_REQUEST_ACTION = 'approve-pull-request',
3738
COMMENT_PR_ACTION = 'comment-pull-request',
3839
COMMENT_PR_LABEL = 'Add Comment',
3940
COMMENT_ISSUE_ACTION = 'comment-issue',
@@ -197,4 +198,22 @@ export enum ModalsEnum {
197198
MULTI_SHARE_GITHUB_ISSUES_INPUT_LABEL = "Issues",
198199
MULTI_SHARE_GITHUB_ISSUES_INPUT_ACTION = "multishare-github-issues-input-action",
199200
GITHUB_LOGIN_ACTION = "github-login-action",
201+
MAIN_MODAL_VIEW = "main-modal-view",
202+
MAIN_MODAL_OPEN_LABLE = "Open",
203+
MAIN_MODAL_TITLE = "GitHub",
204+
TRIGGER_SEARCH_MODAL = "trigger-search-modal",
205+
TRIGGER_NEW_ISSUE_MODAL = "trigger-new-issue-modal",
206+
TRIGGER_SUBSCRIPTIONS_MODAL = "trigger-subscriptions-modal",
207+
TRIGGER_ASSIGN_ISSUES_MODAL = "trigger-assign-issues-modal",
208+
MAIN_MODAL_GITHUB_SEARCH_LABLE = "Github Search",
209+
MAIN_MODAL_GITHUB_SEARCH_DESCRIPTION = "Search Github and share your resources on the channel",
210+
MAIN_MODAL_NEW_ISSUE_LABLE = "New Issues",
211+
MAIN_MODAL_NEW_ISSUE_DESCRIPTION = "Create new issues on Github",
212+
MAIN_MODAL_REPOSITORY_SUBSCRIPTIONS_LABLE = "Repository Subscriptions",
213+
MAIN_MODAL_REPOSITORY_SUBSCRIPTIONS_DESCRIPTION = "Subscribe to repositories Events",
214+
MAIN_MODAL_ASSIGN_ISSUES_LABLE = "Assign Issues",
215+
MAIN_MODAL_ASSIGN_ISSUES_DESCRIPTION = "Assign issues to your team members",
216+
NEW_REMINDER_VIEW = "new-reminder-view",
217+
UNSUBSCRIBE_REMINDER_ACTION = "unsubscribe-reminder-action",
218+
REMINDER_LIST_MODAL_VIEW= "reminder-list-view"
200219
}

0 commit comments

Comments
 (0)