Skip to content

Commit

Permalink
feat: Add Group/File schemas (#506)
Browse files Browse the repository at this point in the history
This commit adds more schemas for TypeScript and continues f1fe376.
  • Loading branch information
Granjow authored and jdalrymple committed Dec 5, 2019
1 parent b709ef6 commit f467816
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/core/services/GroupProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import {
PaginatedRequestOptions,
RequestHelper,
} from '../infrastructure';
import { ProjectSchema } from './Projects';

export class GroupProjects extends BaseService {
all(groupId: string | number, options?: PaginatedRequestOptions) {
all(groupId: string | number, options?: PaginatedRequestOptions): Promise<ProjectSchema[]> {
const gId = encodeURIComponent(groupId);

return RequestHelper.get(this, `groups/${gId}/projects`, options);
return RequestHelper.get(this, `groups/${gId}/projects`, options) as Promise<ProjectSchema[]>;
}

add(groupId: string | number, projectId: string | number, options?: BaseRequestOptions) {
Expand Down
24 changes: 20 additions & 4 deletions src/core/services/Groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,25 @@ import {
} from '../infrastructure';
import { ProjectSchema } from './Projects';

export interface GroupSchema {
id: number;
name: string;
path: string;
full_name: string;
full_path: string;
parent_id: number;
visibility: string;
avatar_url: string;
web_url: string;
}

export interface GroupDetailSchema extends GroupSchema {
projects: ProjectSchema[];
}

export class Groups extends BaseService {
all(options?: PaginatedRequestOptions) {
return RequestHelper.get(this, 'groups', options);
all(options?: PaginatedRequestOptions): Promise<GroupSchema[]> {
return RequestHelper.get(this, 'groups', options) as Promise<GroupSchema[]>;
}

create(options?: BaseRequestOptions) {
Expand Down Expand Up @@ -63,10 +79,10 @@ export class Groups extends BaseService {
});
}

show(groupId: string | number, options?: BaseRequestOptions) {
show(groupId: string | number, options?: BaseRequestOptions): Promise<GroupDetailSchema> {
const gId = encodeURIComponent(groupId);

return RequestHelper.get(this, `groups/${gId}`, options);
return RequestHelper.get(this, `groups/${gId}`, options) as Promise<GroupDetailSchema>;
}

subgroups(groupId: string | number, options?: PaginatedRequestOptions) {
Expand Down
22 changes: 20 additions & 2 deletions src/core/services/RepositoryFiles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import { BaseService, RequestHelper, BaseRequestOptions, Sudo } from '../infrastructure';

export interface RepositoryFileSchema {
file_name: string;
file_path: string;
size: number;
encoding: string;
content: string;
content_sha256: string;
ref: string;
blob_id: string;
commit_id: string;
last_commit_id: string;
}

export class RepositoryFiles extends BaseService {
create(
projectId: string | number,
Expand Down Expand Up @@ -53,13 +66,18 @@ export class RepositoryFiles extends BaseService {
});
}

show(projectId: string | number, filePath: string, ref: string, options?: Sudo) {
show(
projectId: string | number,
filePath: string,
ref: string,
options?: Sudo,
): Promise<RepositoryFileSchema> {
const [pId, path] = [projectId, filePath].map(encodeURIComponent);

return RequestHelper.get(this, `projects/${pId}/repository/files/${path}`, {
ref,
...options,
});
}) as Promise<RepositoryFileSchema>;
}

showBlame(projectId: string | number, filePath: string, options?: Sudo) {
Expand Down

0 comments on commit f467816

Please sign in to comment.