Skip to content
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ dist

# TernJS port file
.tern-port

#RC Server and APP Testing
RC_SERVER
TESTING_APPS
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# Apps.Github22
The ultimate app extending Rocket.Chat for all developers collaborating on Github (2022 and beyond)
# Github
The ultimate app extending Rocket.Chat for all developers collaborating on Github

## Getting Started
Now that you have generated a blank default Rocket.Chat App, what are you supposed to do next?
Start developing! Open up your favorite editor, our recommended one is Visual Studio code,
and start working on your App. Once you have something ready to test, you can either
package it up and manually deploy it to your test instance or you can use the CLI to do so.
Here are some commands to get started:
- `rc-apps package`: this command will generate a packaged app file (zip) which can be installed **if** it compiles with TypeScript
- `rc-apps deploy`: this will do what `package` does but will then ask you for your server url, username, and password to deploy it for you

## Documentation
Here are some links to examples and documentation:
- [Rocket.Chat Apps TypeScript Definitions Documentation](https://rocketchat.github.io/Rocket.Chat.Apps-engine/)
- [Rocket.Chat Apps TypeScript Definitions Repository](https://github.com/RocketChat/Rocket.Chat.Apps-engine)
- [Example Rocket.Chat Apps](https://github.com/graywolf336/RocketChatApps)
- Community Forums
- [App Requests](https://forums.rocket.chat/c/rocket-chat-apps/requests)
- [App Guides](https://forums.rocket.chat/c/rocket-chat-apps/guides)
- [Top View of Both Categories](https://forums.rocket.chat/c/rocket-chat-apps)
- [#rocketchat-apps on Open.Rocket.Chat](https://open.rocket.chat/channel/rocketchat-apps)
16 changes: 16 additions & 0 deletions github/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
indent_style = space
indent_size = 4
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
28 changes: 28 additions & 0 deletions github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ignore modules pulled in from npm
node_modules/

# rc-apps package output
dist/

# JetBrains IDEs
out/
.idea/
.idea_modules/

# macOS
.DS_Store
.AppleDouble
.LSOverride
._*
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
19 changes: 19 additions & 0 deletions github/.rcappsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"url": "http://localhost:3000",
"username": "",
"password": "",
"ignoredFiles": [
"**/README.md",
"**/package-lock.json",
"**/package.json",
"**/tslint.json",
"**/tsconfig.json",
"**/*.js",
"**/*.js.map",
"**/*.d.ts",
"**/*.spec.ts",
"**/*.test.ts",
"**/dist/**",
"**/.*"
]
}
11 changes: 11 additions & 0 deletions github/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"recommendations": [
"EditorConfig.editorconfig",
"eamodio.gitlens",
"eg2.vscode-npm-script",
"wayou.vscode-todo-highlight",
"minhthai.vscode-todo-parser",
"ms-vscode.vscode-typescript-tslint-plugin",
"rbbit.typescript-hero"
]
}
38 changes: 38 additions & 0 deletions github/GithubApp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
IAppAccessors,
IConfigurationExtend,
IHttp,
ILogger,
IModify,
IPersistence,
IRead,
} from "@rocket.chat/apps-engine/definition/accessors";
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 { ExecuteViewClosedHandler } from "./handlers/ExecuteViewClosedHandler";
import { ExecuteBlockActionHandler } from "./handlers/ExecuteBlockActionHandler";

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);
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 extendConfiguration(
configuration: IConfigurationExtend
): Promise<void> {
const gitHubCommand: GithubCommand = new GithubCommand(this);
await configuration.slashCommands.provideSlashCommand(gitHubCommand);
}
}
16 changes: 16 additions & 0 deletions github/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "826f0d95-9e25-48a6-a781-a32f147230a5",
"version": "0.0.1",
"requiredApiVersion": "^1.19.0",
"iconFile": "icon.png",
"author": {
"name": "Samad Yar Khan",
"homepage": "https://github.com/samad-yar-khan",
"support": "https://github.com/samad-yar-khan"
},
"name": "Github",
"nameSlug": "github",
"classFile": "GithubApp.ts",
"description": "The ultimate app extending Rocket.Chat for all developers collaborating on Github",
"implements": []
}
86 changes: 86 additions & 0 deletions github/commands/GithubCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
ISlashCommand,
SlashCommandContext,
} from "@rocket.chat/apps-engine/definition/slashcommands";
import {
IHttp,
IModify,
IPersistence,
IRead,
} from "@rocket.chat/apps-engine/definition/accessors";

import { GithubApp } from "../GithubApp";
import { initiatorMessage } from "../lib/initiatorMessage";
import { helperMessage } from "../lib/helperMessage";
import { basicQueryMessage } from "../helpers/basicQueryMessage";
import { pullDetailsModal } from "../modals/pullDetailsModal";


export class GithubCommand implements ISlashCommand {
public constructor(private readonly app: GithubApp) {}
public command = "github";
public i18nDescription = "fetching githup data";
public providesPreview = false;
public i18nParamsExample = "";

public async executor(
context: SlashCommandContext,
read: IRead,
modify: IModify,
http: IHttp,
persistence: IPersistence
): Promise<void> {

const command = context.getArguments();
const sender = context.getSender();
const room = context.getRoom();

if(!Array.isArray(command)){
return;
}

switch (command?.length) {
case 0:{
await helperMessage({room,read, persistence, modify, http});
break;
}
case 1 : {
const data = {
room: room,
sender: sender,
arguments: command,
};
await initiatorMessage({ data, read, persistence, modify, http });
break;
}
case 2 : {
const repository = command[0];
const query = command[1];
await basicQueryMessage ({query,repository,room,read,persistence,modify,http});
break;
}
case 3 :{
const data = {
repository:command[0],
query:command[1],
number:command[2]
}
const triggerId= context.getTriggerId();
if(triggerId){
console.log(triggerId);
const modal = await pullDetailsModal({data,modify,read,persistence,http,slashcommandcontext:context});
await modify.getUiController().openModalView(modal,{triggerId},context.getSender());
}else{
console.log("Inavlid Trigger ID !");
}
break;
}
default:{
await helperMessage({room,read, persistence, modify, http});
break;
}

}

}
}
6 changes: 6 additions & 0 deletions github/enum/App.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum AppEnum {
DEFAULT_TITLE = 'GitHub',
USERNAME_ALIAS = 'GitHub',
EMOJI_AVATAR = '',
USER_MESSAGED_BOT = 'You have messaged the bot user. This has no effect.',
}
12 changes: 12 additions & 0 deletions github/enum/Modals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export enum ModalsEnum {
PULL_VIEW = 'pull-view',
CODE_VIEW = 'code-view',
VIEW_FILE_ACTION = 'view-file-task',
VIEW_FILE_ACTION_LABEL = 'View File',
VIEW_DIFFS_ACTION_LABEL = 'View Changes',
PULL_VIEW_LABEL = 'Pull Request',
MERGE_PULL_REQUEST_ACTION = 'merge-pull-request',
MERGE_PULL_REQUEST_LABEL = 'Merge',
COMMENT_PR_ACTION = 'comment-pull-request',
COMMENT_PR_LABEL = 'Comment',
}
97 changes: 97 additions & 0 deletions github/handlers/ExecuteBlockActionHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {
IHttp,
ILogger,
IModify,
IPersistence,
IRead,
} from "@rocket.chat/apps-engine/definition/accessors";
import { IApp } from "@rocket.chat/apps-engine/definition/IApp";
import { IRoom } from "@rocket.chat/apps-engine/definition/rooms";
import { basicQueryMessage } from "../helpers/basicQueryMessage";
import { ModalsEnum } from "../enum/Modals";
import { fileCodeModal } from "../modals/fileCodeModal";
import {
IUIKitResponse,
UIKitBlockInteractionContext,
} from "@rocket.chat/apps-engine/definition/uikit";

export class ExecuteBlockActionHandler {
constructor(
private readonly app: IApp,
private readonly read: IRead,
private readonly http: IHttp,
private readonly modify: IModify,
private readonly persistence: IPersistence
) {}

public async run(
context: UIKitBlockInteractionContext
): Promise<IUIKitResponse> {
const data = context.getInteractionData();

const { actionId } = data;

switch (actionId) {
case "githubDataSelect": {
try {
const param = data.value;
let query: String = "";
let lengthOfRepoString: number = 0;
if (param && param.length) {
let i = param.length - 1;
for (
;
i >= 0 && data.value && data.value[i] != "/";
i--
) {
query = data.value[i] + query;
}
lengthOfRepoString = i;
}
const repository = param?.substring(
0,
lengthOfRepoString
) as String;

const room: IRoom = context.getInteractionData()
.room as IRoom;

await basicQueryMessage({
query,
repository,
room,
read: this.read,
persistence: this.persistence,
modify: this.modify,
http: this.http,
});

return {
success: true,
};
} catch (err) {
console.error(err);
return {
success: false,
};
}
break;
}
case ModalsEnum.VIEW_FILE_ACTION: {
const codeModal = await fileCodeModal({
data,
modify: this.modify,
read: this.read,
persistence: this.persistence,
http: this.http,
uikitcontext: context,
});
return context
.getInteractionResponder()
.openModalViewResponse(codeModal);
}
}

return context.getInteractionResponder().successResponse();
}
}
Loading