Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit e7bbbf2

Browse files
author
Noah Hanjun Lee
authored
Update the prefix of Repos API in UI (#138)
1 parent 5663c5e commit e7bbbf2

23 files changed

+270
-366
lines changed

internal/server/slack/notification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (s *Slack) notifyApprovalEvent(ctx context.Context, e *ent.Event) {
9393
return
9494
}
9595

96-
if d = a.Edges.Deployment; d != nil {
96+
if d = a.Edges.Deployment; d == nil {
9797
s.log.Error("The eager loading of deployment has failed.")
9898
return
9999
}

ui/src/apis/approval.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { _fetch } from "./_base"
55
import { UserData, mapDataToUser } from "./user"
66
import { DeploymentData, mapDataToDeployment } from "./deployment"
77
import {
8-
Repo,
98
User,
109
Deployment,
1110
Approval,
@@ -93,8 +92,8 @@ export const searchApprovals = async (statuses: ApprovalStatus[], from?: Date, t
9392
return approvals
9493
}
9594

96-
export const listApprovals = async (id: string, number: number): Promise<Approval[]> => {
97-
const res = await _fetch(`${instance}/api/v1/repos/${id}/deployments/${number}/approvals`, {
95+
export const listApprovals = async (namespace: string, name: string, number: number): Promise<Approval[]> => {
96+
const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approvals`, {
9897
credentials: "same-origin",
9998
headers,
10099
})
@@ -109,11 +108,11 @@ export const listApprovals = async (id: string, number: number): Promise<Approva
109108
return approvals
110109
}
111110

112-
export const createApproval = async (repo: Repo, deployment: Deployment, approver: User): Promise<Approval> => {
111+
export const createApproval = async (namespace: string, name: string, number: number, userId: string): Promise<Approval> => {
113112
const body = {
114-
user_id: approver.id
113+
user_id: userId
115114
}
116-
const res = await _fetch(`${instance}/api/v1/repos/${repo.id}/deployments/${deployment.number}/approvals`, {
115+
const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approvals`, {
117116
credentials: "same-origin",
118117
headers,
119118
method: "POST",
@@ -131,8 +130,8 @@ export const createApproval = async (repo: Repo, deployment: Deployment, approve
131130
return approval
132131
}
133132

134-
export const deleteApproval = async (repo: Repo, approval: Approval): Promise<void> => {
135-
const res = await _fetch(`${instance}/api/v1/repos/${repo.id}/approvals/${approval.id}`, {
133+
export const deleteApproval = async (namespace: string, name: string, id: number): Promise<void> => {
134+
const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/approvals/${id}`, {
136135
credentials: "same-origin",
137136
headers,
138137
method: "DELETE",
@@ -144,8 +143,8 @@ export const deleteApproval = async (repo: Repo, approval: Approval): Promise<vo
144143
}
145144
}
146145

147-
export const getMyApproval = async (id: string, number: number): Promise<Approval> => {
148-
const res = await _fetch(`${instance}/api/v1/repos/${id}/deployments/${number}/approval`, {
146+
export const getMyApproval = async (namespace: string, name: string, number: number): Promise<Approval> => {
147+
const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approval`, {
149148
credentials: "same-origin",
150149
headers,
151150
})
@@ -159,11 +158,11 @@ export const getMyApproval = async (id: string, number: number): Promise<Approva
159158
return approval
160159
}
161160

162-
export const setApprovalApproved = async (id: string, number: number): Promise<Approval> => {
161+
export const setApprovalApproved = async (namespace: string, name: string, number: number): Promise<Approval> => {
163162
const body = {
164163
status: ApprovalStatus.Approved.toString(),
165164
}
166-
const res = await _fetch(`${instance}/api/v1/repos/${id}/deployments/${number}/approval`, {
165+
const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approval`, {
167166
credentials: "same-origin",
168167
headers,
169168
method: "PATCH",
@@ -179,11 +178,11 @@ export const setApprovalApproved = async (id: string, number: number): Promise<A
179178
return approval
180179
}
181180

182-
export const setApprovalDeclined = async (id: string, number: number): Promise<Approval> => {
181+
export const setApprovalDeclined = async (namespace: string, name: string, number: number): Promise<Approval> => {
183182
const body = {
184183
status: ApprovalStatus.Declined.toString(),
185184
}
186-
const res = await _fetch(`${instance}/api/v1/repos/${id}/deployments/${number}/approval`, {
185+
const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approval`, {
187186
credentials: "same-origin",
188187
headers,
189188
method: "PATCH",

ui/src/apis/branch.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const mapDataToBranch = (data: BranchData): Branch => {
1616
}
1717
}
1818

19-
export const listBranches = async (repoId: string, page = 1, perPage = 30): Promise<Branch[]> => {
20-
const branches: Branch[] = await _fetch(`${instance}/api/v1/repos/${repoId}/branches?page=${page}&per_page=${perPage}`, {
19+
export const listBranches = async (namespace: string, name: string, page = 1, perPage = 30): Promise<Branch[]> => {
20+
const branches: Branch[] = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/branches?page=${page}&per_page=${perPage}`, {
2121
headers,
2222
credentials: "same-origin",
2323
})
@@ -27,8 +27,8 @@ export const listBranches = async (repoId: string, page = 1, perPage = 30): Prom
2727
return branches
2828
}
2929

30-
export const getBranch = async (repoId: string, name: string): Promise<Branch> => {
31-
const response = await _fetch(`${instance}/api/v1/repos/${repoId}/branches/${name}`, {
30+
export const getBranch = async (namespace: string, name: string, branch: string): Promise<Branch> => {
31+
const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/branches/${branch}`, {
3232
headers,
3333
credentials: "same-origin",
3434
})
@@ -37,9 +37,9 @@ export const getBranch = async (repoId: string, name: string): Promise<Branch> =
3737
throw new HttpNotFoundError(message)
3838
}
3939

40-
const branch:Branch = await response
40+
const ret:Branch = await response
4141
.json()
4242
.then((b: BranchData) => mapDataToBranch(b))
4343

44-
return branch
44+
return ret
4545
}

ui/src/apis/commit.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ const mapStatusState = (state: string) => {
6363
return StatusState.Pending
6464
}
6565

66-
export const listCommits = async (repoId: string, branch: string, page = 1, perPage = 30): Promise<Commit[]> => {
67-
const commits: Commit[] = await _fetch(`${instance}/api/v1/repos/${repoId}/commits?branch=${branch}&page=${page}&per_page=${perPage}`, {
66+
export const listCommits = async (namespace: string, name: string, branch: string, page = 1, perPage = 30): Promise<Commit[]> => {
67+
const commits: Commit[] = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/commits?branch=${branch}&page=${page}&per_page=${perPage}`, {
6868
headers,
6969
credentials: "same-origin",
7070
})
@@ -74,8 +74,8 @@ export const listCommits = async (repoId: string, branch: string, page = 1, perP
7474
return commits
7575
}
7676

77-
export const getCommit = async (repoId: string, sha: string): Promise<Commit> => {
78-
const response = await _fetch(`${instance}/api/v1/repos/${repoId}/commits/${sha}`, {
77+
export const getCommit = async (namespace: string, name: string, sha: string): Promise<Commit> => {
78+
const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/commits/${sha}`, {
7979
headers,
8080
credentials: "same-origin",
8181
})
@@ -91,8 +91,8 @@ export const getCommit = async (repoId: string, sha: string): Promise<Commit> =>
9191
return commit
9292
}
9393

94-
export const listStatuses = async (repoId: string, sha: string): Promise<{state: StatusState, statuses: Status[]}> => {
95-
const response = await _fetch(`${instance}/api/v1/repos/${repoId}/commits/${sha}/statuses`, {
94+
export const listStatuses = async (namespace: string, name: string, sha: string): Promise<{state: StatusState, statuses: Status[]}> => {
95+
const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/commits/${sha}/statuses`, {
9696
headers,
9797
credentials: "same-origin",
9898
})

ui/src/apis/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const mapDataToConfig = (data: ConfigData): Config => {
4040
}
4141
}
4242

43-
export const getConfig = async (repoId: string): Promise<Config> => {
44-
const response = await _fetch(`${instance}/api/v1/repos/${repoId}/config`, {
43+
export const getConfig = async (namespace: string, name: string): Promise<Config> => {
44+
const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/config`, {
4545
headers,
4646
credentials: "same-origin",
4747
})

ui/src/apis/deployment.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ export const searchDeployments = async (statuses: DeploymentStatusEnum[], owned:
169169
return deployments
170170
}
171171

172-
export const listDeployments = async (repoId: string, env: string, status: string, page: number, perPage: number): Promise<Deployment[]> => {
173-
const deployments: Deployment[] = await _fetch(`${instance}/api/v1/repos/${repoId}/deployments?env=${env}&status=${status}&page=${page}&per_page=${perPage}`, {
172+
export const listDeployments = async (namespace: string, name: string, env: string, status: string, page: number, perPage: number): Promise<Deployment[]> => {
173+
const deployments: Deployment[] = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments?env=${env}&status=${status}&page=${page}&per_page=${perPage}`, {
174174
headers,
175175
credentials: 'same-origin',
176176
})
@@ -180,8 +180,8 @@ export const listDeployments = async (repoId: string, env: string, status: strin
180180
return deployments
181181
}
182182

183-
export const getDeployment = async (id: string, number: number): Promise<Deployment> => {
184-
const deployment = await _fetch(`${instance}/api/v1/repos/${id}/deployments/${number}`, {
183+
export const getDeployment = async (namespace: string, name: string, number: number): Promise<Deployment> => {
184+
const deployment = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}`, {
185185
headers,
186186
credentials: 'same-origin',
187187
})
@@ -191,13 +191,13 @@ export const getDeployment = async (id: string, number: number): Promise<Deploym
191191
return deployment
192192
}
193193

194-
export const createDeployment = async (repoId: string, type: DeploymentType = DeploymentType.Commit, ref: string, env: string): Promise<Deployment> => {
194+
export const createDeployment = async (namespace: string, name: string, type: DeploymentType = DeploymentType.Commit, ref: string, env: string): Promise<Deployment> => {
195195
const body = JSON.stringify({
196196
type,
197197
ref,
198198
env
199199
})
200-
const response = await _fetch(`${instance}/api/v1/repos/${repoId}/deployments`, {
200+
const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments`, {
201201
headers,
202202
credentials: 'same-origin',
203203
method: "POST",
@@ -220,11 +220,11 @@ export const createDeployment = async (repoId: string, type: DeploymentType = De
220220
return deployment
221221
}
222222

223-
export const updateDeploymentStatusCreated = async (id: string, number: number): Promise<Deployment> => {
223+
export const updateDeploymentStatusCreated = async (namespace: string, name: string, number: number): Promise<Deployment> => {
224224
const body = JSON.stringify({
225225
status: "created"
226226
})
227-
const response = await _fetch(`${instance}/api/v1/repos/${id}/deployments/${number}`, {
227+
const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}`, {
228228
headers,
229229
credentials: 'same-origin',
230230
method: "PATCH",
@@ -244,8 +244,8 @@ export const updateDeploymentStatusCreated = async (id: string, number: number):
244244
return deployment
245245
}
246246

247-
export const rollbackDeployment = async (repoId: string, number: number): Promise<Deployment> => {
248-
const response = await _fetch(`${instance}/api/v1/repos/${repoId}/deployments/${number}/rollback`, {
247+
export const rollbackDeployment = async (namespace: string, name: string, number: number): Promise<Deployment> => {
248+
const response = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/rollback`, {
249249
headers,
250250
credentials: 'same-origin',
251251
method: "POST",
@@ -267,8 +267,8 @@ export const rollbackDeployment = async (repoId: string, number: number): Promis
267267
return deployment
268268
}
269269

270-
export const listDeploymentChanges = async (repoId: string, number: number, page = 1, perPage = 30): Promise<Commit[]> => {
271-
const res = await _fetch(`${instance}/api/v1/repos/${repoId}/deployments/${number}/changes?page=${page}&per_page=${perPage}`, {
270+
export const listDeploymentChanges = async (namespace: string, name: string, number: number, page = 1, perPage = 30): Promise<Commit[]> => {
271+
const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/changes?page=${page}&per_page=${perPage}`, {
272272
headers,
273273
credentials: 'same-origin',
274274
})

ui/src/apis/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { sync } from "./sync"
22
import {
33
listRepos,
4-
searchRepo,
4+
getRepo,
55
updateRepo,
66
activateRepo,
77
deactivateRepo,
@@ -44,7 +44,7 @@ import { subscribeEvents } from "./events"
4444
export {
4545
sync,
4646
listRepos,
47-
searchRepo,
47+
getRepo,
4848
updateRepo,
4949
activateRepo,
5050
deactivateRepo,

ui/src/apis/lock.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { StatusCodes } from "http-status-codes"
33
import { instance, headers } from "./setting"
44
import { _fetch } from "./_base"
55
import { UserData, mapDataToUser } from "./user"
6-
import { Repo, Lock, User, HttpForbiddenError, HttpUnprocessableEntityError } from "../models"
6+
import { Lock, User, HttpForbiddenError, HttpUnprocessableEntityError } from "../models"
77

88
interface LockData {
99
id: number
@@ -29,8 +29,8 @@ const mapDataToLock = (data: LockData): Lock => {
2929
}
3030
}
3131

32-
export const listLocks = async (repo: Repo): Promise<Lock[]> => {
33-
const locks = await _fetch(`${instance}/api/v1/repos/${repo.id}/locks`, {
32+
export const listLocks = async (namespace: string, name: string): Promise<Lock[]> => {
33+
const locks = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/locks`, {
3434
headers,
3535
credentials: 'same-origin',
3636
})
@@ -40,8 +40,8 @@ export const listLocks = async (repo: Repo): Promise<Lock[]> => {
4040
return locks
4141
}
4242

43-
export const lock = async (repo: Repo, env: string): Promise<Lock> => {
44-
const res = await _fetch(`${instance}/api/v1/repos/${repo.id}/locks`, {
43+
export const lock = async (namespace: string, name: string, env: string): Promise<Lock> => {
44+
const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/locks`, {
4545
headers,
4646
credentials: 'same-origin',
4747
method: "POST",
@@ -62,8 +62,8 @@ export const lock = async (repo: Repo, env: string): Promise<Lock> => {
6262
return lock
6363
}
6464

65-
export const unlock = async (repo: Repo, lock: Lock): Promise<void> => {
66-
const res = await _fetch(`${instance}/api/v1/repos/${repo.id}/locks/${lock.id}`, {
65+
export const unlock = async (namespace: string, name: string, id: number): Promise<void> => {
66+
const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/locks/${id}`, {
6767
headers,
6868
credentials: 'same-origin',
6969
method: "DELETE",

ui/src/apis/perm.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { instance, headers } from './setting'
22
import { _fetch } from "./_base"
33
import { mapDataToUser, UserData } from "./user"
44
import { mapDataToRepo, RepoData } from "./repo"
5-
import { Repo, Perm } from '../models'
5+
import { Perm } from '../models'
66

77
interface PermData{
88
repo_perm: string
@@ -26,8 +26,8 @@ const mapDataToPerm = (data: PermData): Perm => {
2626
}
2727
}
2828

29-
export const listPerms = async (repo: Repo, q: string, page = 1, perPage = 30): Promise<Perm[]> => {
30-
const perms: Perm[] = await _fetch(`${instance}/api/v1/repos/${repo.id}/perms?q=${q}&page=${page}&per_page=${perPage}`, {
29+
export const listPerms = async (namespace: string, name: string, q: string, page = 1, perPage = 30): Promise<Perm[]> => {
30+
const perms: Perm[] = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/perms?q=${q}&page=${page}&per_page=${perPage}`, {
3131
headers,
3232
credentials: "same-origin"
3333
})

0 commit comments

Comments
 (0)