-
Notifications
You must be signed in to change notification settings - Fork 39
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
[Feat]: Add new GithubSDK class #144
Merged
samad-yar-khan
merged 9 commits into
RocketChat:main
from
VipinDevelops:feat/enterprise-server-support
Apr 13, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cd8c81f
Store setting info in persistence
VipinDevelops ab7a436
migrate get userinfo and get request
VipinDevelops 0d8197a
use the enum
VipinDevelops c90944e
add proper handler for userinfo
VipinDevelops 96d5367
add new Appsetting enum
VipinDevelops 937bd99
fix label id and appsetting enum
VipinDevelops 4937e24
remove syantax changes
VipinDevelops e8dd750
Merge branch 'main' into feat/enterprise-server-support
VipinDevelops 109aae3
use direct settings
VipinDevelops File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,9 @@ | ||
export interface UserInformation { | ||
username: string; | ||
name: string; | ||
email: string; | ||
bio: string; | ||
followers: string; | ||
following: string; | ||
avatar: string; | ||
} |
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,54 @@ | ||
import { IHttp, HttpStatusCode, IRead } from "@rocket.chat/apps-engine/definition/accessors"; | ||
import { UserInfo } from "os"; | ||
import { UserInformation } from "../definitions/Userinfo"; | ||
import { ModalsEnum } from "../enum/Modals"; | ||
|
||
class GitHubApi { | ||
private http: IHttp; | ||
private BaseHost: string; | ||
private BaseApiHost: string; | ||
private accessToken: String; | ||
|
||
constructor(http: IHttp, accessToken: String, BaseHost: string, BaseApiHost: string) { | ||
this.http = http; | ||
this.accessToken = accessToken; | ||
this.BaseApiHost = BaseApiHost; | ||
this.BaseHost = BaseHost; | ||
} | ||
|
||
private async getRequest(url: string): Promise<any> { | ||
const response = await this.http.get(url, { | ||
headers: { | ||
Authorization: `token ${this.accessToken}`, | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
if (!response.statusCode.toString().startsWith("2")) { | ||
throw response; | ||
} | ||
|
||
return JSON.parse(response.content || "{}"); | ||
} | ||
|
||
public async getBasicUserInfo(): Promise<UserInformation> { | ||
try { | ||
const response = await this.getRequest( | ||
this.BaseApiHost + 'user' | ||
); | ||
return { | ||
username: response.login, | ||
name: response.name, | ||
email: response.email, | ||
bio: response.bio, | ||
followers: response.followers, | ||
following: response.following, | ||
avatar: response.avatar_url | ||
} | ||
} catch (error) { | ||
throw error; | ||
} | ||
} | ||
} | ||
|
||
export { GitHubApi }; |
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 |
---|---|---|
@@ -1,16 +1,39 @@ | ||
import { ISetting, SettingType } from '@rocket.chat/apps-engine/definition/settings'; | ||
|
||
export enum AppSettings{ | ||
ReminderCRONjobString = 'reminderCronJobString' | ||
export enum AppSettingsEnum { | ||
ReminderCRONjobID = 'reminder_cron_job_id', | ||
ReminderCRONjobLabel = 'cron_job_string_for_pr_reminders_label', | ||
ReminderCRONjobPackageValue = '0 9 * * *', | ||
BaseHostID = "base_host_id", | ||
BaseHostLabel = "base_host_label", | ||
BaseHostPackageValue = "https://github.com/", | ||
BaseApiHostID = "base_api_host_id", | ||
BaseApiHostLabel = "base_api_host_label", | ||
BaseApiHostPackageValue = "https://api.github.com/" | ||
} | ||
|
||
export const settings: ISetting[] = [ | ||
{ | ||
id: AppSettings.ReminderCRONjobString, | ||
i18nLabel: 'cron-job-string-for-pr-reminders', | ||
type: SettingType.STRING, | ||
required: true, | ||
public: false, | ||
packageValue: '0 9 * * *', | ||
}, | ||
{ | ||
id: AppSettingsEnum.ReminderCRONjobID, | ||
i18nLabel: AppSettingsEnum.ReminderCRONjobLabel, | ||
type: SettingType.STRING, | ||
required: true, | ||
public: false, | ||
packageValue: AppSettingsEnum.ReminderCRONjobPackageValue, | ||
}, | ||
{ | ||
id: AppSettingsEnum.BaseHostID, | ||
i18nLabel: AppSettingsEnum.BaseHostLabel, | ||
type: SettingType.STRING, | ||
required: true, | ||
public: false, | ||
packageValue: AppSettingsEnum.BaseHostPackageValue, | ||
}, | ||
{ | ||
id: AppSettingsEnum.BaseApiHostID, | ||
i18nLabel: AppSettingsEnum.BaseApiHostLabel, | ||
type: SettingType.STRING, | ||
required: true, | ||
public: false, | ||
packageValue: AppSettingsEnum.BaseApiHostPackageValue, | ||
}, | ||
]; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
try response.ok() ..probably is available
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.
Sorry that isn't available