-
Notifications
You must be signed in to change notification settings - Fork 41
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 #144 from VipinDevelops/feat/enterprise-server-sup…
…port [Feat]: Add new GithubSDK class
- Loading branch information
Showing
6 changed files
with
130 additions
and
33 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,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, | ||
}, | ||
]; |