Skip to content

Commit

Permalink
Merge branch 'jobatzil/swagger-raw' of _OKE5H2PQKOUfzFFDuD4FA/default…
Browse files Browse the repository at this point in the history
…/CODE/gitness (#30)
  • Loading branch information
johannesHarness authored and Harness committed Apr 18, 2023
2 parents f9d0fe1 + cd9b8f1 commit 958ace2
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 18 deletions.
13 changes: 13 additions & 0 deletions internal/api/openapi/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,19 @@ func repoOperations(reflector *openapi3.Reflector) {
_ = reflector.SetJSONResponse(&opGetContent, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{repo_ref}/content/{path}", opGetContent)

opGetRaw := openapi3.Operation{}
opGetRaw.WithTags("repository")
opGetRaw.WithMapOfAnything(map[string]interface{}{"operationId": "getRaw"})
opGetRaw.WithParameters(queryParameterGitRef)
_ = reflector.SetRequest(&opGetRaw, new(getContentRequest), http.MethodGet)
// TODO: Figure out how to provide proper list of all potential mime types
_ = reflector.SetStringResponse(&opGetRaw, http.StatusOK, "")
_ = reflector.SetJSONResponse(&opGetRaw, new(usererror.Error), http.StatusInternalServerError)
_ = reflector.SetJSONResponse(&opGetRaw, new(usererror.Error), http.StatusUnauthorized)
_ = reflector.SetJSONResponse(&opGetRaw, new(usererror.Error), http.StatusForbidden)
_ = reflector.SetJSONResponse(&opGetRaw, new(usererror.Error), http.StatusNotFound)
_ = reflector.Spec.AddOperation(http.MethodGet, "/repos/{repo_ref}/raw/{path}", opGetRaw)

opGetBlame := openapi3.Operation{}
opGetBlame.WithTags("repository")
opGetBlame.WithMapOfAnything(map[string]interface{}{"operationId": "getBlame"})
Expand Down
2 changes: 2 additions & 0 deletions internal/api/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ func JSON(w http.ResponseWriter, code int, v interface{}) {
}

// Reader reads the content from the provided reader and writes it as is to the response body.
// NOTE: If no content-type header is added beforehand, the content-type will be deduced
// automatically by `http.DetectContentType` (https://pkg.go.dev/net/http#DetectContentType).
func Reader(ctx context.Context, w http.ResponseWriter, code int, reader io.Reader) {
w.WriteHeader(code)
_, err := io.Copy(w, reader)
Expand Down
58 changes: 51 additions & 7 deletions web/src/services/code/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type EnumPathTargetType = string

export type EnumPrincipalType = 'service' | 'serviceaccount' | 'user'

export type EnumPullReqActivityKind = 'code' | 'comment' | 'system'
export type EnumPullReqActivityKind = 'change-comment' | 'comment' | 'system'

export type EnumPullReqActivityType =
| 'branch-delete'
Expand Down Expand Up @@ -106,14 +106,19 @@ export interface OpenapiCalculateCommitDivergenceRequest {
}

export interface OpenapiCommentCreatePullReqRequest {
line_end?: number
line_end_new?: boolean
line_start?: number
line_start_new?: boolean
parent_id?: number
payload?: TypesPullRequestActivityPayloadComment
path?: string
source_commit_sha?: string
target_commit_sha?: string
text?: string
}

export interface OpenapiCommentUpdatePullReqRequest {
payload?: TypesPullRequestActivityPayloadComment
text?: string | null
text?: string
}

export interface OpenapiCommitFilesRequest {
Expand Down Expand Up @@ -328,6 +333,7 @@ export type RepoContentType = string

export interface RepoFileContent {
data?: string
data_size?: number
encoding?: EnumContentEncodingType
size?: number
}
Expand Down Expand Up @@ -413,13 +419,21 @@ export interface TypesPullReq {

export interface TypesPullReqActivity {
author?: TypesPrincipalInfo
code_comment_line_new?: number | null
code_comment_line_old?: number | null
code_comment_merge_base_sha?: string | null
code_comment_path?: string | null
code_comment_source_sha?: string | null
code_comment_span_new?: number | null
code_comment_span_old?: number | null
created?: number
deleted?: number | null
edited?: number
id?: number
kind?: EnumPullReqActivityKind
metadata?: { [key: string]: any } | null
order?: number
outdated?: boolean | null
parent_id?: number | null
payload?: {}
pullreq_id?: number
Expand All @@ -437,8 +451,6 @@ export interface TypesPullReqStats {
files_changed?: number
}

export type TypesPullRequestActivityPayloadComment = { [key: string]: any } | null

export interface TypesRepository {
created?: number
created_by?: number
Expand Down Expand Up @@ -1639,7 +1651,7 @@ export interface ListPullReqActivitiesQueryParams {
/**
* The kind of the pull request activity to include in the result.
*/
kind?: ('code' | 'comment' | 'system')[]
kind?: ('change-comment' | 'comment' | 'system')[]
/**
* The type of the pull request activity to include in the result.
*/
Expand Down Expand Up @@ -2134,6 +2146,38 @@ export const useStatePullReq = ({ repo_ref, pullreq_number, ...props }: UseState
{ base: getConfig('code'), pathParams: { repo_ref, pullreq_number }, ...props }
)

export interface GetRawQueryParams {
/**
* The git reference (branch / tag / commitID) that will be used to retrieve the data. If no value is provided the default branch of the repository is used.
*/
git_ref?: string
}

export interface GetRawPathParams {
repo_ref: string
path: string
}

export type GetRawProps = Omit<GetProps<void, UsererrorError, GetRawQueryParams, GetRawPathParams>, 'path'> &
GetRawPathParams

export const GetRaw = ({ repo_ref, path, ...props }: GetRawProps) => (
<Get<void, UsererrorError, GetRawQueryParams, GetRawPathParams>
path={`/repos/${repo_ref}/raw/${path}`}
base={getConfig('code')}
{...props}
/>
)

export type UseGetRawProps = Omit<UseGetProps<void, UsererrorError, GetRawQueryParams, GetRawPathParams>, 'path'> &
GetRawPathParams

export const useGetRaw = ({ repo_ref, path, ...props }: UseGetRawProps) =>
useGet<void, UsererrorError, GetRawQueryParams, GetRawPathParams>(
(paramsInPath: GetRawPathParams) => `/repos/${paramsInPath.repo_ref}/raw/${paramsInPath.path}`,
{ base: getConfig('code'), pathParams: { repo_ref, path }, ...props }
)

export interface ListRepositoryServiceAccountsPathParams {
repo_ref: string
}
Expand Down
105 changes: 94 additions & 11 deletions web/src/services/code/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,7 @@ paths:
schema:
items:
enum:
- code
- change-comment
- comment
- system
type: string
Expand Down Expand Up @@ -2340,6 +2340,58 @@ paths:
description: Internal Server Error
tags:
- pullreq
/repos/{repo_ref}/raw/{path}:
get:
operationId: getRaw
parameters:
- description: The git reference (branch / tag / commitID) that will be used
to retrieve the data. If no value is provided the default branch of the
repository is used.
in: query
name: git_ref
required: false
schema:
default: '{Repository Default Branch}'
type: string
- in: path
name: repo_ref
required: true
schema:
type: string
- in: path
name: path
required: true
schema:
type: string
responses:
'200':
description: OK
'401':
content:
application/json:
schema:
$ref: '#/components/schemas/UsererrorError'
description: Unauthorized
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/UsererrorError'
description: Forbidden
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/UsererrorError'
description: Not Found
'500':
content:
application/json:
schema:
$ref: '#/components/schemas/UsererrorError'
description: Internal Server Error
tags:
- repository
/repos/{repo_ref}/service-accounts:
get:
operationId: listRepositoryServiceAccounts
Expand Down Expand Up @@ -3647,7 +3699,7 @@ components:
type: string
EnumPullReqActivityKind:
enum:
- code
- change-comment
- comment
- system
type: string
Expand Down Expand Up @@ -3796,19 +3848,28 @@ components:
type: object
OpenapiCommentCreatePullReqRequest:
properties:
line_end:
type: integer
line_end_new:
type: boolean
line_start:
type: integer
line_start_new:
type: boolean
parent_id:
type: integer
payload:
$ref: '#/components/schemas/TypesPullRequestActivityPayloadComment'
path:
type: string
source_commit_sha:
type: string
target_commit_sha:
type: string
text:
type: string
type: object
OpenapiCommentUpdatePullReqRequest:
properties:
payload:
$ref: '#/components/schemas/TypesPullRequestActivityPayloadComment'
text:
nullable: true
type: string
type: object
OpenapiCommitFilesRequest:
Expand Down Expand Up @@ -4177,6 +4238,8 @@ components:
properties:
data:
type: string
data_size:
type: integer
encoding:
$ref: '#/components/schemas/EnumContentEncodingType'
size:
Expand Down Expand Up @@ -4324,6 +4387,27 @@ components:
properties:
author:
$ref: '#/components/schemas/TypesPrincipalInfo'
code_comment_line_new:
nullable: true
type: integer
code_comment_line_old:
nullable: true
type: integer
code_comment_merge_base_sha:
nullable: true
type: string
code_comment_path:
nullable: true
type: string
code_comment_source_sha:
nullable: true
type: string
code_comment_span_new:
nullable: true
type: integer
code_comment_span_old:
nullable: true
type: integer
created:
type: integer
deleted:
Expand All @@ -4341,6 +4425,9 @@ components:
type: object
order:
type: integer
outdated:
nullable: true
type: boolean
parent_id:
nullable: true
type: integer
Expand Down Expand Up @@ -4370,10 +4457,6 @@ components:
files_changed:
type: integer
type: object
TypesPullRequestActivityPayloadComment:
additionalProperties: {}
nullable: true
type: object
TypesRepository:
properties:
created:
Expand Down

0 comments on commit 958ace2

Please sign in to comment.