@@ -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";
1215import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata" ;
1316import { GithubCommand } from "./commands/GithubCommand" ;
1417import {
18+ ButtonStyle ,
1519 IUIKitResponse ,
1620 UIKitBlockInteractionContext ,
1721 UIKitViewCloseInteractionContext ,
@@ -27,30 +31,74 @@ import {
2731 IOAuth2ClientOptions ,
2832} from "@rocket.chat/apps-engine/definition/oauth2/IOAuth2" ;
2933import { createOAuth2Client } from "@rocket.chat/apps-engine/definition/oauth2/OAuth2" ;
30- import { createSectionBlock } from "./lib/blocks" ;
3134import {
3235 sendDirectMessage ,
3336 sendDirectMessageOnInstall ,
37+ sendMessage ,
3438 sendNotification ,
3539} from "./lib/message" ;
36- import { OAuth2Client } from "@rocket.chat/apps-engine/server/oauth2/OAuth2Client" ;
3740import { deleteOathToken } from "./processors/deleteOAthToken" ;
3841import { ProcessorsEnum } from "./enum/Processors" ;
3942import {
4043 ApiSecurity ,
4144 ApiVisibility ,
4245} from "@rocket.chat/apps-engine/definition/api" ;
4346import { 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" ;
4548import { IRoom } from "@rocket.chat/apps-engine/definition/rooms" ;
4649import { clearInteractionRoomData , getInteractionRoomData } from "./persistance/roomInteraction" ;
4750import { 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}
0 commit comments