forked from RocketChat/Apps.Github22
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request RocketChat#41 from Nabhag8848/repo-validation
[FIX] commands and buttons, unexpected results when repository in github doesn't exist
- Loading branch information
Showing
4 changed files
with
157 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { | ||
IHttp, | ||
IModify, | ||
IRead, | ||
} from "@rocket.chat/apps-engine/definition/accessors"; | ||
import { GithubApp } from "../GithubApp"; | ||
import { isRepositoryExist } from "../helpers/githubSDK"; | ||
import { getAccessTokenForUser } from "../persistance/auth"; | ||
import { IUser } from "@rocket.chat/apps-engine/definition/users"; | ||
import { IRoom } from "@rocket.chat/apps-engine/definition/rooms"; | ||
import { IAuthData } from "@rocket.chat/apps-engine/definition/oauth2/IOAuth2"; | ||
|
||
export async function HandleInvalidRepoName( | ||
repoName: string, | ||
http: IHttp, | ||
app: GithubApp, | ||
modify: IModify, | ||
sender: IUser, | ||
read: IRead, | ||
room: IRoom | ||
): Promise<boolean> { | ||
const accessToken = (await getAccessTokenForUser( | ||
read, | ||
sender, | ||
app.oauth2Config | ||
)) as IAuthData; | ||
|
||
const isValidRepository: boolean = await isRepositoryExist( | ||
http, | ||
repoName, | ||
accessToken?.token | ||
); | ||
|
||
if (!isValidRepository) { | ||
const warningBuilder = await modify | ||
.getCreator() | ||
.startMessage() | ||
.setRoom(room); | ||
|
||
if (accessToken) { | ||
warningBuilder.setText( | ||
`Hey ${sender.username}! Provided repository doesn't exist.` | ||
); | ||
} else { | ||
warningBuilder.setText( | ||
`Hey ${sender.username}! Provided repository doesn't exist or you need to login to access private repo.` | ||
); | ||
} | ||
|
||
if (room.type !== "l") { | ||
await modify | ||
.getNotifier() | ||
.notifyUser(sender, warningBuilder.getMessage()); | ||
} else { | ||
await modify.getCreator().finish(warningBuilder); | ||
} | ||
} | ||
|
||
return isValidRepository; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters