Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
814aef4
Add new EMUN values for modal
samad-yar-khan Jun 19, 2022
595e0ed
Oath2 Module
samad-yar-khan Jun 26, 2022
7b31492
Implimennt OAth2 With Scheduler to delete tokens periodically
samad-yar-khan Jun 28, 2022
4a7373a
Add Revoke Token ToDO
samad-yar-khan Jun 29, 2022
9429297
Add github sdk for event subscriptions
samad-yar-khan Jul 2, 2022
caca3bd
updat esubscribe logic
samad-yar-khan Jul 3, 2022
e63008e
Add subscription persitence logic
samad-yar-khan Jul 3, 2022
9c89c28
Add slash command subscription logic
samad-yar-khan Jul 3, 2022
fe0615e
unsubscribe logic
samad-yar-khan Jul 3, 2022
2b1186e
Add Room Interaction perisstance functiosn for modals
samad-yar-khan Jul 4, 2022
f3b888f
add subscirpion modal
samad-yar-khan Jul 4, 2022
2e7242b
Complete Subscriptions modal
samad-yar-khan Jul 4, 2022
db8782d
Add New Subscription Modal
samad-yar-khan Jul 4, 2022
ac96152
Add Subsciption submit handler
samad-yar-khan Jul 4, 2022
cc72cb6
Add Deelete Subscibtion
samad-yar-khan Jul 4, 2022
18677f2
Delete Subscription
samad-yar-khan Jul 4, 2022
dd30353
Add Deployment status message
samad-yar-khan Jul 4, 2022
64124d9
Add Update Webhook events logic
samad-yar-khan Jul 4, 2022
b91e628
Add- Open updated subsscriptons moda;
samad-yar-khan Jul 4, 2022
cc388a4
Enable common webhook for repo logic
samad-yar-khan Jul 5, 2022
9409c5c
add refresh button
samad-yar-khan Jul 5, 2022
1f625a8
Remove Comments
samad-yar-khan Jul 5, 2022
21add2d
Add Linting - proper tabs, remove white spaces
samad-yar-khan Jul 5, 2022
fd47b66
Remove extra lines
samad-yar-khan Jul 5, 2022
40bef12
Add Multiroom Same hook subscription logic
samad-yar-khan Jul 5, 2022
74c9fa3
Update Helper Message
samad-yar-khan Jul 5, 2022
dca2215
New Add Subscription Title
samad-yar-khan Jul 6, 2022
b74dc26
Send Login Message as Notification in Same RToom
samad-yar-khan Jul 6, 2022
5cb8dc1
Rmoeve native module support
samad-yar-khan Jul 12, 2022
d159ee2
Add More Isuue/PR payload actions
samad-yar-khan Jul 15, 2022
d25e6ad
Handlee unauthenticatd request
samad-yar-khan Jul 16, 2022
4dc6c2d
Add Logout Slash Command
samad-yar-khan Jul 16, 2022
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
169 changes: 163 additions & 6 deletions github/GithubApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,186 @@ import {
import { App } from "@rocket.chat/apps-engine/definition/App";
import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata";
import { GithubCommand } from "./commands/GithubCommand";
import { IUIKitResponse, UIKitBlockInteractionContext, UIKitViewCloseInteractionContext } from '@rocket.chat/apps-engine/definition/uikit';
import {
IUIKitResponse,
UIKitBlockInteractionContext,
UIKitViewCloseInteractionContext,
UIKitViewSubmitInteractionContext,
} from "@rocket.chat/apps-engine/definition/uikit";
import { ExecuteViewClosedHandler } from "./handlers/ExecuteViewClosedHandler";
import { ExecuteBlockActionHandler } from "./handlers/ExecuteBlockActionHandler";
import { ExecuteViewSubmitHandler } from "./handlers/ExecuteViewSubmitHandler";
import { IUser } from "@rocket.chat/apps-engine/definition/users";
import {
IAuthData,
IOAuth2Client,
IOAuth2ClientOptions,
} from "@rocket.chat/apps-engine/definition/oauth2/IOAuth2";
import { createOAuth2Client } from "@rocket.chat/apps-engine/definition/oauth2/OAuth2";
import { createSectionBlock } from "./lib/blocks";
import { sendDirectMessage, sendNotification } from "./lib/message";
import { OAuth2Client } from "@rocket.chat/apps-engine/server/oauth2/OAuth2Client";
import { deleteOathToken } from "./processors/deleteOAthToken";
import { ProcessorsEnum } from "./enum/Processors";
import {
ApiSecurity,
ApiVisibility,
} from "@rocket.chat/apps-engine/definition/api";
import { githubWebHooks } from "./endpoints/githubEndpoints";
import { IJobContext } from "@rocket.chat/apps-engine/definition/scheduler";
import { IRoom } from "@rocket.chat/apps-engine/definition/rooms";
import { clearInteractionRoomData, getInteractionRoomData } from "./persistance/roomInteraction";

export class GithubApp extends App {
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
}

public async executeBlockActionHandler(context: UIKitBlockInteractionContext, read: IRead, http: IHttp, persistence: IPersistence, modify: IModify): Promise<IUIKitResponse> {
const handler = new ExecuteBlockActionHandler(this, read, http, modify, persistence);
public async authorizationCallback(
token: IAuthData,
user: IUser,
read: IRead,
modify: IModify,
http: IHttp,
persistence: IPersistence
) {
const deleteTokenTask = {
id: ProcessorsEnum.REMOVE_GITHUB_LOGIN,
when: "7 days",
data: {
user: user,
config: this.oauth2Config,
},
};
let text = `GitHub Authentication Succesfull 🚀`;
let interactionData = await getInteractionRoomData(read.getPersistenceReader(),user.id) ;

if (token) {
// await registerAuthorizedUser(read, persistence, user);
await modify.getScheduler().scheduleOnce(deleteTokenTask);
} else {
text = `Authentication Failure 😔`;
}
if(interactionData && interactionData.roomId){
let roomId = interactionData.roomId as string;
let room = await read.getRoomReader().getById(roomId) as IRoom;
await clearInteractionRoomData(persistence,user.id);
await sendNotification(read,modify,user,room,text);
}else{
await sendDirectMessage(read, modify, user, text, persistence);
}

}
public oauth2ClientInstance: IOAuth2Client;
public oauth2Config: IOAuth2ClientOptions = {
alias: "github-app",
accessTokenUri: "https://github.com/login/oauth/access_token",
authUri: "https://github.com/login/oauth/authorize",
refreshTokenUri: "https://github.com/login/oauth/access_token",
revokeTokenUri: `https://api.github.com/applications/client_id/token`,
authorizationCallback: this.authorizationCallback.bind(this),
defaultScopes: ["users", "repo"],
};
public getOauth2ClientInstance(): IOAuth2Client {
if (!this.oauth2ClientInstance) {
this.oauth2ClientInstance = createOAuth2Client(
this,
this.oauth2Config
);
}
return this.oauth2ClientInstance;
}

public async executeBlockActionHandler(
context: UIKitBlockInteractionContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify
): Promise<IUIKitResponse> {
const handler = new ExecuteBlockActionHandler(
this,
read,
http,
modify,
persistence
);
return await handler.run(context);
}

public async executeViewClosedHandler(
context: UIKitViewCloseInteractionContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify
) {
const handler = new ExecuteViewClosedHandler(
this,
read,
http,
modify,
persistence
);
return await handler.run(context);
}

public async executeViewClosedHandler(context: UIKitViewCloseInteractionContext, read: IRead, http: IHttp, persistence: IPersistence, modify: IModify) {
const handler = new ExecuteViewClosedHandler(this, read, http, modify, persistence);
public async executeViewSubmitHandler(
context: UIKitViewSubmitInteractionContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify
) {
const handler = new ExecuteViewSubmitHandler(
this,
read,
http,
modify,
persistence
);
return await handler.run(context);
}

public async extendConfiguration(
configuration: IConfigurationExtend
): Promise<void> {
const gitHubCommand: GithubCommand = new GithubCommand(this);
await configuration.slashCommands.provideSlashCommand(gitHubCommand);
await Promise.all([
configuration.slashCommands.provideSlashCommand(gitHubCommand),
this.getOauth2ClientInstance().setup(configuration),
]);
configuration.scheduler.registerProcessors([
{
id: ProcessorsEnum.REMOVE_GITHUB_LOGIN,
processor: async (jobContext, read, modify, http, persis) => {
let user = jobContext.user as IUser;
let config = jobContext.config as IOAuth2ClientOptions;
try {
await deleteOathToken({
user,
config,
read,
modify,
http,
persis,
});
} catch (e) {
await sendDirectMessage(
read,
modify,
user,
e.message,
persis
);
}
},
},
]);
configuration.api.provideApi({
visibility: ApiVisibility.PUBLIC,
security: ApiSecurity.UNSECURE,
endpoints: [new githubWebHooks(this)],
});
}
}
Loading