-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
136 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
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,65 +1,73 @@ | ||
import { appendQuery } from './utils'; | ||
|
||
class GitHub { | ||
|
||
constructor(options) { | ||
const { client_id, client_secret } = options; | ||
this.client_id = client_id; | ||
this.client_secret = client_secret; | ||
} | ||
|
||
client_id = '' | ||
|
||
client_secret = '' | ||
|
||
/** | ||
* 是否登陆 | ||
* | ||
* @memberof GitHub | ||
*/ | ||
ifLogin = false | ||
|
||
/** | ||
* 去github获取权限 | ||
* | ||
* @param {string} client_id | ||
* @memberof GitHub | ||
*/ | ||
login(client_id) { | ||
let url = 'https://github.com/login/oauth/authorize'; | ||
url = appendQuery(url, { | ||
client_id, | ||
redirect_uri: window.location.href, | ||
scope: 'public_repo' | ||
}); | ||
window.location.href = url; | ||
} | ||
import http from './http'; | ||
import { getQuery, appendQuery } from "./utils"; | ||
import state from '../state'; | ||
|
||
/** | ||
* 找到第一个符合的issue | ||
* | ||
* @export | ||
* @param {string} owner 仓库所有者 | ||
* @param {string} repo 仓库名称 | ||
* @param {string} labels labels 用逗号分隔 | ||
* @returns {any>} | ||
*/ | ||
export function getFirstIssue(owner, repo, labels) { | ||
return http.get(`/repos/${owner}/${repo}/issues`, { | ||
creator: owner, | ||
labels | ||
}).then(body => JSON.parse(body)[0]); | ||
} | ||
|
||
const github = { | ||
/** | ||
* 是否登陆 | ||
*/ | ||
ifLogin: false, | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {string} owner | ||
* @param {string} repo | ||
* @param {number} number | ||
* @returns | ||
*/ | ||
export function getIssue(owner, repo, number) { | ||
return http.get(`/repos/${owner}/${repo}/issues/${number}`) | ||
.then(body => JSON.parse(body)); | ||
} | ||
|
||
token: '', | ||
/** | ||
* 获取token | ||
* | ||
* @export | ||
* @param {string} client_id | ||
* @param {string} client_secret | ||
* @param {string} code | ||
* @returns {Promise<string>} | ||
*/ | ||
export function getToken(client_id, client_secret, code) { | ||
return http | ||
.post('https://github.com/login/oauth/access_token', { | ||
client_id: state.client_id, | ||
client_secret: state.client_secret, | ||
code | ||
}, true) | ||
.then(body => getQuery(body, 'access_token')); | ||
} | ||
|
||
/** | ||
* 去github获取权限 | ||
* | ||
* @param {string} client_id | ||
*/ | ||
login(client_id) { | ||
let url = 'https://github.com/login/oauth/authorize'; | ||
url = appendQuery(url, { | ||
client_id, | ||
redirect_uri: window.location.href, | ||
scope: 'public_repo' | ||
}); | ||
window.location.href = url; | ||
console.log(url); | ||
} | ||
}; | ||
/** | ||
* 跳转去认证 | ||
* | ||
* @export | ||
* @param {string} client_id | ||
*/ | ||
export function toAuthorize(client_id) { | ||
let url = 'https://github.com/login/oauth/authorize'; | ||
url = appendQuery(url, { | ||
client_id: client_id, | ||
redirect_uri: window.location.href, | ||
scope: 'public_repo', | ||
state: window.location.href | ||
}); | ||
window.location.href = url; | ||
} | ||
|
||
export default github; | ||
export function getAuthUser() { | ||
return http.get('/user'); | ||
} |
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 was deleted.
Oops, something went wrong.
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,15 @@ | ||
/** | ||
* 当前状态和全局数据 | ||
*/ | ||
export default { | ||
client_id: '', | ||
|
||
client_secret: '', | ||
|
||
access_token: '', | ||
|
||
/** | ||
* 是否登录 | ||
*/ | ||
ifLogin: false | ||
}; |