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

[Function] Code Sharing in Channel and to Github Repository & UI Redesign & Compatible with New Server #37

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

RyanbowZ
Copy link
Collaborator

This PR mainly focus on developing the sharing functions. It not only allows users to share within the RC channel, but also allows users to upload their generated code pieces to Github repository. An interactive user interface has also been designed and implemented.

Meanwhile, we redesigned the contextual bar to be compatible with the newest RC server version 6.11 while resolving other issues mentioned by reviewers previously to improve quality.

Issue(s)

This PR's function updates closed #29 #30 #31 #32 #33 #34 #35 #36 .

Acceptance Criteria fulfillment

  • Update the UI logics to compatible with the new version of RC server (6.11)
  • Redesign the entire contextual bar (dropdown box) to use the compatible ui-kit features.
  • Allow users to share their generated code content into current channel.
  • Enable the connection with their Github repository using OAuth2 for authentication.
  • Allow users to share their generated code content to the Github repository by specifying the corresponding branch, file path, repo name, etc.
  • Users can edit their content before any sharing functions.
  • The modal window will be closed immediately after pressing buttons.

Proposed Changes

Since the newest RC server has become 6.11, where old contextual bar interface becomes incompatible. The UI logic has to be changed, and the entire contextual bar is redesigned to be more user-friendly and compatible with this new version server.

In this PR we mainly enables the sharing functions. Firstly, it allows users to share within the RC channel by sending message containing the generated code content. Secondly, it further uses OAuth2 features of App-engine to configure user's access tokens with Github, and then allows users to upload their generated code pieces to Github repository.

To implement this connection with Github repository, I researched on Samad Khan 's Github22 app and I finally figured out the implementation of uploading user's generated code into files to the Github repository, branch and path specified by the user. I also adopt the OAuth2 features of App-engine to configure user's access tokens with Github. Users need to setup their Github connections in the same way the authenticated in Github22 app.

An interactive user interface has also been designed and implemented. In both sharing functions, users have the ability of editing and verifying the content before the content become public. Now the modal windows will be directly closed after pressing the button to avoid block user's focus on information in channels.

Additionally, several code glitches are resolved, unnecessary comments are removed, modal action handling logics are changed according to reviewer's feedbacks.

Results

Screen.Recording.2024-08-11.at.21.57.56.mov

Copy link
Collaborator

@samad-yar-khan samad-yar-khan left a comment

Choose a reason for hiding this comment

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

I think there is a lot of unnecessary code copy pasted from the other repo.

definition/ui-kit/Modals/createMainContextualBar.ts Outdated Show resolved Hide resolved
definition/ui-kit/Modals/generateCodeModal.ts Outdated Show resolved Hide resolved
definition/ui-kit/Modals/regenerateCodeModal.ts Outdated Show resolved Hide resolved
enum/Modals.ts Outdated Show resolved Hide resolved
enum/Processors.ts Outdated Show resolved Hide resolved
persistance/auth.ts Outdated Show resolved Hide resolved
@samad-yar-khan
Copy link
Collaborator

samad-yar-khan commented Aug 11, 2024

@RyanbowZ

  • Although this code works to push the snippet to a repo, it seems hard to use.
  • If I have to go to github to know a file and location, I can just edit the code on gh, why do I even need to use this feature.
  • Idk how this overwrite will work incase the file already has code.
  • The input boxes are a bit large for entering repo names, m sure there is a smaller input field component that can be used for names and branch.
  • An ideal UI would be one that shows me the directory structure in app and I am able to figure out what to do from rocket chat itself.
  • As discussed in out channel, this seems more fit for saving code snippets as gist ?

Copy link
Collaborator

@samad-yar-khan samad-yar-khan left a comment

Choose a reason for hiding this comment

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

Please refer to above comments regarding code and functionality

AiProgrammerApp.ts Outdated Show resolved Hide resolved
handlers/ExecuteActionButtonHandler.ts Outdated Show resolved Hide resolved
settings/settings.ts Outdated Show resolved Hide resolved
AiProgrammerApp.ts Outdated Show resolved Hide resolved
AiProgrammerApp.ts Outdated Show resolved Hide resolved
definition/Reminder.ts Outdated Show resolved Hide resolved
handlers/ExecuteViewSubmitHandler.ts Outdated Show resolved Hide resolved
}
}

return false;

Choose a reason for hiding this comment

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

This whole code is for sending reminders form github app,
Please don't copy paste code without understanding it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@RyanbowZ was this addressed ?

@@ -0,0 +1,139 @@
import {
IPersistence,

Choose a reason for hiding this comment

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

Again this code is not Not relevant to this app

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

deleted

settings/settings.ts Show resolved Hide resolved
settings/settings.ts Outdated Show resolved Hide resolved
@VipinDevelops
Copy link

Hey @RyanbowZ,

I tested the "Share to Gist" feature with @samad-yar-khan, and we found a bug in the current code. If someone wants to share the gist and doesn't change the initial value of the modal, the value will be passed as empty.

I have encountered a similar bug in my code and have a solution.

What you need to do is store the gist content in persistent storage for each user with a unique ID. If the user wants to share the code to Gist and hasn't changed anything in the initial value, the state will show it as undefined. To make it work, you just have to check if the user made any changes (meaning the view state changed). If so, use the view state values; otherwise, use the value stored in persistence for the code.

Here is a code snippet for it from my Project : ExecuteViewSubmitHandler.ts#L246-L282

);
break;
}
case "gist": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

set as Enum

}
}

return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@RyanbowZ was this addressed ?

Comment on lines +1 to +21
import { IGithubReactions } from "./githubReactions"

//inidividual issue
export interface IGitHubIssue{
issue_id: string|number,
title?: string,
html_url?: string,
number?: string|number
labels?: Array<string>,
user_login?:string,
user_avatar?:string,
last_updated_at?: string,
comments?:string|number,
state?: string,
share?: boolean,//true if seacrh result is to be shareed
assignees?: Array<string>,//user ids seperated by " "
issue_compact: string,//compact string to share issues in rooms
repo_url?: string,
body?: string,
reactions? : IGithubReactions
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@RyanbowZ are you even using any of these ?

Comment on lines +1 to +107
import {
IApiEndpointInfo,
IApiEndpoint,
IApiRequest,
IApiResponse,
} from "@rocket.chat/apps-engine/definition/api";
import { Subscription } from "../persistance/subscriptions";
import { ISubscription } from "../definition/subscription";
import { IRoom } from "@rocket.chat/apps-engine/definition/rooms";
export class githubWebHooks extends ApiEndpoint {
public path = "githubwebhook";

public async post(
request: IApiRequest,
endpoint: IApiEndpointInfo,
read: IRead,
modify: IModify,
http: IHttp,
persis: IPersistence
): Promise<IApiResponse> {
let event: string = request.headers["x-github-event"] as string;
let payload: any;
if (
request.headers["content-type"] ===
"application/x-www-form-urlencoded"
) {
payload = JSON.parse(request.content.payload);
} else {
payload = request.content;
}

let subscriptionStorage = new Subscription(
persis,
read.getPersistenceReader()
);

const subscriptions: Array<ISubscription> =
await subscriptionStorage.getSubscribedRooms(
payload.repository.full_name,
event
);
if (!subscriptions || subscriptions.length == 0) {
return this.success();
}
const eventCaps = event.toUpperCase();
let messageText = "newEvent !";

if (event == "push") {
messageText = `*New Commits to* *[${payload.repository.full_name}](${payload.repository.html_url}) by ${payload.pusher.name}*`;
} else if (event == "pull_request") {
if(payload.action == "opened"){
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}]*`;
}else if(payload.action == "closed" && payload.pull_request.merged ){
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}]*`;
}else if(payload.action == "closed" && !payload.pull_request.merged){
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}]*`;
}else if(payload.action =="reopened"){
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}]*`;
}else{
return this.success();
}
} else if (event == "issues") {
if(payload.action == "opened"){
messageText = `*[New Issue](${payload.issue.html_url})* *|* *#${payload.issue.number}* *${payload.issue.title}* *|* *[${payload.repository.full_name}](${payload.repository.html_url})* `;
}else if(payload.action == "closed"){
messageText = `*[Issue Closed](${payload.issue.html_url})* *|* *#${payload.issue.number}* *${payload.issue.title}* *|* *[${payload.repository.full_name}](${payload.repository.html_url})* `;
}else if(payload.action == "reopened"){
messageText = `*[ReOpened Issue](${payload.issue.html_url})* *|* *#${payload.issue.number}* *${payload.issue.title}* *|* *[${payload.repository.full_name}](${payload.repository.html_url})* `;
}else{
return this.success();
}
} else if (event == "deployment_status") {
messageText = `*Deployment Status ${payload.deployment_status.state}* *|* *${payload.repository.full_name}*`;
} else if (event == "star"){
if(payload?.action == "created"){
messageText = `*New Stars on* *${payload.repository.full_name}* *|* *${payload.repository.stargazers_count}* ⭐`;
}else{
return this.success();
}
}
for (let subscription of subscriptions) {
let roomId = subscription.room;
if (!roomId) {
continue;
}
const room: IRoom = (await read
.getRoomReader()
.getById(roomId)) as IRoom;
const textSender = await modify
.getCreator()
.startMessage()
.setText(messageText);
if (room) {
textSender.setRoom(room);
}
await modify.getCreator().finish(textSender);
}

return this.success();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@RyanbowZ are you using any of these ? its a webhook code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Allow users to share code to Github repository
4 participants