refactor: clean up github and rewrite its auth
This commit is contained in:
28
packages/backend/src/apps/github/common/generate-request.ts
Normal file
28
packages/backend/src/apps/github/common/generate-request.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
import { Method } from 'axios';
|
||||
|
||||
type IGenereateRequestOptons = {
|
||||
requestPath: string;
|
||||
method: string;
|
||||
data?: IJSONObject;
|
||||
};
|
||||
|
||||
const generateRequest = async (
|
||||
$: IGlobalVariable,
|
||||
options: IGenereateRequestOptons
|
||||
) => {
|
||||
const { requestPath, method, data } = options;
|
||||
|
||||
const response = await $.http.request({
|
||||
url: requestPath,
|
||||
method: method as Method,
|
||||
data,
|
||||
headers: {
|
||||
Authorization: `Bearer ${$.auth.data.accessToken}`
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
export default generateRequest;
|
14
packages/backend/src/apps/github/common/get-current-user.ts
Normal file
14
packages/backend/src/apps/github/common/get-current-user.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
import generateRequest from './generate-request';
|
||||
|
||||
const getCurrentUser = async ($: IGlobalVariable): Promise<IJSONObject> => {
|
||||
const response = await generateRequest($, {
|
||||
requestPath: '/user',
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
const currentUser = response.data;
|
||||
return currentUser;
|
||||
};
|
||||
|
||||
export default getCurrentUser;
|
@@ -0,0 +1,13 @@
|
||||
type TRepoOwnerAndRepo = {
|
||||
repoOwner: string;
|
||||
repo: string;
|
||||
}
|
||||
|
||||
export function getRepoOwnerAndRepo(repoFullName: string): TRepoOwnerAndRepo {
|
||||
const [repoOwner, repo] = repoFullName.split('/');
|
||||
|
||||
return {
|
||||
repoOwner,
|
||||
repo
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user