From 5a73f97a83c15e5a962e3bbbf4618241e1a16b77 Mon Sep 17 00:00:00 2001 From: Nabhag Motivaras Date: Thu, 1 Jun 2023 20:38:44 +0530 Subject: [PATCH 1/3] feat: Init OnInstall --- github/GithubApp.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/github/GithubApp.ts b/github/GithubApp.ts index 8659bde..cf32d58 100644 --- a/github/GithubApp.ts +++ b/github/GithubApp.ts @@ -1,5 +1,6 @@ import { IAppAccessors, + IAppInstallationContext, IConfigurationExtend, IHttp, ILogger, @@ -63,7 +64,10 @@ export class GithubApp extends App { }, }; let text = `GitHub Authentication Succesfull 🚀`; - let interactionData = await getInteractionRoomData(read.getPersistenceReader(),user.id) ; + let interactionData = await getInteractionRoomData( + read.getPersistenceReader(), + user.id + ); if (token) { // await registerAuthorizedUser(read, persistence, user); @@ -71,15 +75,14 @@ export class GithubApp extends App { } else { text = `Authentication Failure 😔`; } - if(interactionData && interactionData.roomId){ + 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{ + 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 = { @@ -195,4 +198,11 @@ export class GithubApp extends App { endpoints: [new githubWebHooks(this)], }); } + public async onInstall( + context: IAppInstallationContext, + read: IRead, + http: IHttp, + persistence: IPersistence, + modify: IModify + ): Promise {} } From 5d29bf6191f74e3fe8bcd4924bbb139d7de55c77 Mon Sep 17 00:00:00 2001 From: Nabhag Motivaras Date: Wed, 7 Jun 2023 18:37:45 +0530 Subject: [PATCH 2/3] feat: HelperMessage OnInstallation with Feedback Link --- github/GithubApp.ts | 11 +++++++-- github/lib/message.ts | 54 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/github/GithubApp.ts b/github/GithubApp.ts index cf32d58..d9765c9 100644 --- a/github/GithubApp.ts +++ b/github/GithubApp.ts @@ -28,7 +28,11 @@ import { } 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 { + sendDirectMessage, + sendDirectMessageOnInstall, + sendNotification, +} from "./lib/message"; import { OAuth2Client } from "@rocket.chat/apps-engine/server/oauth2/OAuth2Client"; import { deleteOathToken } from "./processors/deleteOAthToken"; import { ProcessorsEnum } from "./enum/Processors"; @@ -204,5 +208,8 @@ export class GithubApp extends App { http: IHttp, persistence: IPersistence, modify: IModify - ): Promise {} + ): Promise { + const user = context.user; + await sendDirectMessageOnInstall(read, modify, user, persistence); + } } diff --git a/github/lib/message.ts b/github/lib/message.ts index dcf872f..4931182 100644 --- a/github/lib/message.ts +++ b/github/lib/message.ts @@ -94,4 +94,56 @@ export async function sendDirectMessage( export function isUserHighHierarchy(user: IUser): boolean { const clearanceList = ['admin', 'owner', 'moderator']; return user.roles.some((role) => clearanceList.includes(role)); -} \ No newline at end of file +} + +export async function sendDirectMessageOnInstall( + read: IRead, + modify: IModify, + user: IUser, + persistence: IPersistence +) { + if (user.roles.includes("admin")) { + const message = ` + Hello **${user.name}!** Thank you for installing the **GitHub Rocket.Chat App**. + + Here's some important information to get you started: + + \xa0\xa0• **Quick and Easy Setup**: You can log in to GitHub with just one click using the built-in OAuth2 mechanism. + \xa0\xa0• **Stay Updated**: Subscribe to Repository Events to receive notifications about new issues, pull requests, and more. + \xa0\xa0• **Review and Merge Pull Requests**: You can conveniently review and merge pull requests directly from RocketChat Channels. + \xa0\xa0• **Create and Manage Issues**: Create new issues from RocketChat and easily search and share existing issues and pull requests using extensive filters. + \xa0\xa0• **Slash Commands**: Access the app using the slash commands \`/gh\` or \`/github\`. + + To assist you further, here are some helpful commands you can use: + + 1. See Interactive Button interface to fetch repository data -> \`/github Username/RepositoryName\` + 2. Get details of a Repository -> \`/github Username/RepositoryName repo\` + 3. Get Issues of a Repository -> \`/github Username/RepositoryName issues\` + 4. Get Contributors of a Repository -> \`/github Username/RepositoryName contributors\` + 5. Get Recent Pull Request of a Repository -> \`/github Username/RepositoryName pulls\` + 6. Review a Pull Request -> \`/github Username/RepositoryName pulls pullNumber\` + 7. Login to GitHub -> \`/github login\` + 8. Logout from GitHub -> \`/github logout\` + 9. View your GitHub Profile and Issues -> \`/github me\` + 10. View/Add/Delete/Update Repository Subscriptions -> \`/github subscribe\` + 11. Subscribe to all repository events -> \`/github Username/RepositoryName subscribe\` + 12. Unsubscribe to all repository events -> \`/github Username/RepositoryName unsubscribe\` + 13. Add New Issues to GitHub Repository -> \`/github issue\` + 14. Search Issues and Pull Requests -> \`/github search\` + 15. Assign and Share Issues -> \`/github issues\` + + To unlock the full potential of the GitHub App, you need to set up a **GitHub OAuth App**. Follow these steps: + + \xa0\xa0• Set up a GitHub OAuth2 App by following the instructions provided. + \xa0\xa0• Ensure the callback URL is set to your server's URL (Note: Remove any trailing '/' at the end of the hosted URL if authentication issues occur). + \xa0\xa0• Once the GitHub OAuth app is set up, access the GitHub Application Settings and enter the GitHub App OAuth Client Id and Client Secret. + + We hope it enhances your collaboration and workflow. We would love to hear your feedback on your experience with the app. + Your feedback helps us improve and provide a better user experience. + Please visit the link to [**provide your feedback**](https://github.com/RocketChat/Apps.Github22/issues) + + Happy collaborating with GitHub and RocketChat :rocket: + `; + await sendDirectMessage(read, modify, user, message, persistence); + } +} From 83bfa9baaac34a3ff58031f54115b4a86f9e03ac Mon Sep 17 00:00:00 2001 From: Nabhag Motivaras Date: Thu, 8 Jun 2023 11:05:30 +0530 Subject: [PATCH 3/3] docs: removed bulky commands text and assist to use help param --- github/lib/message.ts | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/github/lib/message.ts b/github/lib/message.ts index 4931182..9c6dd9b 100644 --- a/github/lib/message.ts +++ b/github/lib/message.ts @@ -114,35 +114,17 @@ export async function sendDirectMessageOnInstall( \xa0\xa0• **Create and Manage Issues**: Create new issues from RocketChat and easily search and share existing issues and pull requests using extensive filters. \xa0\xa0• **Slash Commands**: Access the app using the slash commands \`/gh\` or \`/github\`. - To assist you further, here are some helpful commands you can use: - - 1. See Interactive Button interface to fetch repository data -> \`/github Username/RepositoryName\` - 2. Get details of a Repository -> \`/github Username/RepositoryName repo\` - 3. Get Issues of a Repository -> \`/github Username/RepositoryName issues\` - 4. Get Contributors of a Repository -> \`/github Username/RepositoryName contributors\` - 5. Get Recent Pull Request of a Repository -> \`/github Username/RepositoryName pulls\` - 6. Review a Pull Request -> \`/github Username/RepositoryName pulls pullNumber\` - 7. Login to GitHub -> \`/github login\` - 8. Logout from GitHub -> \`/github logout\` - 9. View your GitHub Profile and Issues -> \`/github me\` - 10. View/Add/Delete/Update Repository Subscriptions -> \`/github subscribe\` - 11. Subscribe to all repository events -> \`/github Username/RepositoryName subscribe\` - 12. Unsubscribe to all repository events -> \`/github Username/RepositoryName unsubscribe\` - 13. Add New Issues to GitHub Repository -> \`/github issue\` - 14. Search Issues and Pull Requests -> \`/github search\` - 15. Assign and Share Issues -> \`/github issues\` - - To unlock the full potential of the GitHub App, you need to set up a **GitHub OAuth App**. Follow these steps: - + To assist you further, use the power of \`/github help\` to unlock a world of enhanced teamwork + + To unlock the full potential of the GitHub App, you need to set up a **GitHub OAuth App**. Follow these steps: \xa0\xa0• Set up a GitHub OAuth2 App by following the instructions provided. \xa0\xa0• Ensure the callback URL is set to your server's URL (Note: Remove any trailing '/' at the end of the hosted URL if authentication issues occur). \xa0\xa0• Once the GitHub OAuth app is set up, access the GitHub Application Settings and enter the GitHub App OAuth Client Id and Client Secret. We hope it enhances your collaboration and workflow. We would love to hear your feedback on your experience with the app. - Your feedback helps us improve and provide a better user experience. - Please visit the link to [**provide your feedback**](https://github.com/RocketChat/Apps.Github22/issues) + Your feedback helps us improve and provide a better user experience. Please visit the link to [**provide your feedback**](https://github.com/RocketChat/Apps.Github22/issues) - Happy collaborating with GitHub and RocketChat :rocket: + Happy collaborating with \`GitHub\` and \`RocketChat\` :rocket: `; await sendDirectMessage(read, modify, user, message, persistence); }