-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
…ub sharing extract code content
There was a problem hiding this 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.
|
There was a problem hiding this 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
handlers/SendReminder.ts
Outdated
} | ||
} | ||
|
||
return false; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RyanbowZ was this addressed ?
persistance/remind.ts
Outdated
@@ -0,0 +1,139 @@ | |||
import { | |||
IPersistence, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted
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": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set as Enum
handlers/SendReminder.ts
Outdated
} | ||
} | ||
|
||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RyanbowZ was this addressed ?
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 | ||
} |
There was a problem hiding this comment.
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 ?
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(); | ||
} |
There was a problem hiding this comment.
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
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
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