refactor: clean up github and rewrite its auth

This commit is contained in:
Ali BARIN
2022-10-16 19:49:45 +02:00
parent a69cd51dda
commit 314787f39c
37 changed files with 398 additions and 1756 deletions

View 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;

View 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;

View File

@@ -0,0 +1,13 @@
type TRepoOwnerAndRepo = {
repoOwner: string;
repo: string;
}
export function getRepoOwnerAndRepo(repoFullName: string): TRepoOwnerAndRepo {
const [repoOwner, repo] = repoFullName.split('/');
return {
repoOwner,
repo
};
}