Skip to content

Commit 97e6f31

Browse files
committed
feat: change oauth token to personal token
1 parent 22c9451 commit 97e6f31

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ACTIONS, { dispatch } from './utils/actions';
55
import { proxyCtx } from './utils/proxy';
66
import toast from './utils/toast';
77

8-
const accessToken = '1b7fca3bd7594a89b0f5e2a0250c1147';
8+
const accessToken = '7e4d9d17f87875e731d536d13635a700ddf52b12';
99
const user = {
1010
id: 8005956,
1111
avatar: 'https://coding-net-production-static-ci.codehub.cn/WM-TEXT-AVATAR-lvVeBfbGLtCPdcsAOPod.jpg',

src/init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export function registerCommands(context: IContext) {
4242
prompt: '请输入仓库名',
4343
});
4444
const team = codingServer.session?.user?.team;
45-
const result = await codingServer.createDepot(team, depot, depot);
46-
// TODO: 拉取代码,更新workspace
45+
await codingServer.createDepot(team, depot, depot);
46+
toast.info('仓库创建成功');
4747
}),
4848
);
4949
}

src/services/codingServer.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export default class CodingServer {
2424
return this._session;
2525
}
2626

27-
get repo() {
28-
return this._repo;
29-
}
27+
getHeaders = (token?: string) => ({
28+
Authorization: `token ${token || this._session.accessToken}`,
29+
});
3030

3131
static async getRepoParams() {
3232
const folders = await hx.workspace.getWorkspaceFolders();
@@ -49,9 +49,7 @@ export default class CodingServer {
4949
const result = await axios({
5050
method: 'get',
5151
url: `https://${team}.coding.net/api/current_user`,
52-
params: {
53-
access_token: token,
54-
},
52+
headers: this.getHeaders(),
5553
});
5654

5755
return result?.data;
@@ -66,13 +64,13 @@ export default class CodingServer {
6664
const result = await axios({
6765
method: 'get',
6866
url,
67+
headers: this.getHeaders(),
6968
params: {
7069
status: `open`,
7170
sort: `action_at`,
7271
page: 1,
7372
PageSize: 100,
7473
sortDirection: `DESC`,
75-
access_token: this._session.accessToken,
7674
},
7775
});
7876
return result?.data?.list || [];
@@ -87,9 +85,7 @@ export default class CodingServer {
8785
const result = await axios({
8886
method: 'get',
8987
url: `https://${team}.coding.net/api/user/${team}/project/${project}/repos`,
90-
params: {
91-
access_token: this._session.accessToken,
92-
},
88+
headers: this.getHeaders(),
9389
});
9490

9591
return result?.data?.depots || [];
@@ -102,7 +98,8 @@ export default class CodingServer {
10298
try {
10399
const result = await axios({
104100
method: 'post',
105-
url: `https://${team}.coding.net/api/team/${team}/template-project?access_token=${this._session.accessToken}`,
101+
url: `https://${team}.coding.net/api/team/${team}/template-project`,
102+
headers: this.getHeaders(),
106103
data: {
107104
name: project,
108105
displayName: project,
@@ -123,9 +120,10 @@ export default class CodingServer {
123120

124121
const result = await axios({
125122
method: 'post',
126-
url: `https://${team}.coding.net/api/user/${team}/project/${project}/depot?access_token=${this._session.accessToken}`,
123+
url: `https://${team}.coding.net/api/user/${team}/project/${project}/depot`,
127124
headers: {
128125
'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
126+
...this.getHeaders(),
129127
},
130128
data: qs.stringify({
131129
name: depot,

0 commit comments

Comments
 (0)