Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(server): Github Branches Webhook & Rest & Controller #65

Merged
merged 12 commits into from
Dec 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
README.md
api.module.ts
api/api.ts
api/branch-controller.service.ts
api/branch-controller.serviceInterface.ts
api/pull-request-controller.service.ts
api/pull-request-controller.serviceInterface.ts
api/status-controller.service.ts
Expand All @@ -10,6 +12,7 @@ configuration.ts
encoder.ts
git_push.sh
index.ts
model/branch-info-dto.ts
model/models.ts
model/pull-request-info-dto.ts
model/repository-info-dto.ts
Expand Down
5 changes: 4 additions & 1 deletion client/src/app/core/modules/openapi/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export * from './branch-controller.service';
import { BranchControllerService } from './branch-controller.service';
export * from './branch-controller.serviceInterface';
export * from './pull-request-controller.service';
import { PullRequestControllerService } from './pull-request-controller.service';
export * from './pull-request-controller.serviceInterface';
export * from './status-controller.service';
import { StatusControllerService } from './status-controller.service';
export * from './status-controller.serviceInterface';
export const APIS = [PullRequestControllerService, StatusControllerService];
export const APIS = [BranchControllerService, PullRequestControllerService, StatusControllerService];
155 changes: 155 additions & 0 deletions client/src/app/core/modules/openapi/api/branch-controller.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/**
* Helios API
*
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/* tslint:disable:no-unused-variable member-ordering */

import { Inject, Injectable, Optional } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams,
HttpResponse, HttpEvent, HttpParameterCodec, HttpContext
} from '@angular/common/http';
import { CustomHttpParameterCodec } from '../encoder';
import { Observable } from 'rxjs';

// @ts-ignore
import { BranchInfoDTO } from '../model/branch-info-dto';

// @ts-ignore
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
import { Configuration } from '../configuration';
import {
BranchControllerServiceInterface
} from './branch-controller.serviceInterface';



@Injectable({
providedIn: 'root'
})
export class BranchControllerService implements BranchControllerServiceInterface {

protected basePath = 'http://localhost';
public defaultHeaders = new HttpHeaders();
public configuration = new Configuration();
public encoder: HttpParameterCodec;

constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string|string[], @Optional() configuration: Configuration) {
if (configuration) {
this.configuration = configuration;
}
if (typeof this.configuration.basePath !== 'string') {
const firstBasePath = Array.isArray(basePath) ? basePath[0] : undefined;
if (firstBasePath != undefined) {
basePath = firstBasePath;
}

if (typeof basePath !== 'string') {
basePath = this.basePath;
}
this.configuration.basePath = basePath;
}
this.encoder = this.configuration.encoder || new CustomHttpParameterCodec();
}


// @ts-ignore
private addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams {
if (typeof value === "object" && value instanceof Date === false) {
httpParams = this.addToHttpParamsRecursive(httpParams, value);
} else {
httpParams = this.addToHttpParamsRecursive(httpParams, value, key);
}
return httpParams;
}

private addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams {
if (value == null) {
return httpParams;
}

if (typeof value === "object") {
if (Array.isArray(value)) {
(value as any[]).forEach( elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key));
} else if (value instanceof Date) {
if (key != null) {
httpParams = httpParams.append(key, (value as Date).toISOString().substring(0, 10));
} else {
throw Error("key may not be null if value is Date");
}
} else {
Object.keys(value).forEach( k => httpParams = this.addToHttpParamsRecursive(
httpParams, value[k], key != null ? `${key}.${k}` : k));
}
} else if (key != null) {
httpParams = httpParams.append(key, value);
} else {
throw Error("key may not be null if value is not object or array");
}
return httpParams;
}

/**
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public getAllBranches(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<Array<BranchInfoDTO>>;
public getAllBranches(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<Array<BranchInfoDTO>>>;
public getAllBranches(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<Array<BranchInfoDTO>>>;
public getAllBranches(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<any> {

let localVarHeaders = this.defaultHeaders;

let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
if (localVarHttpHeaderAcceptSelected === undefined) {
// to determine the Accept header
const httpHeaderAccepts: string[] = [
'application/json'
];
localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
}
if (localVarHttpHeaderAcceptSelected !== undefined) {
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
}

let localVarHttpContext: HttpContext | undefined = options && options.context;
if (localVarHttpContext === undefined) {
localVarHttpContext = new HttpContext();
}

let localVarTransferCache: boolean | undefined = options && options.transferCache;
if (localVarTransferCache === undefined) {
localVarTransferCache = true;
}


let responseType_: 'text' | 'json' | 'blob' = 'json';
if (localVarHttpHeaderAcceptSelected) {
if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
responseType_ = 'text';
} else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) {
responseType_ = 'json';
} else {
responseType_ = 'blob';
}
}

let localVarPath = `/api/branches`;
return this.httpClient.request<Array<BranchInfoDTO>>('get', `${this.configuration.basePath}${localVarPath}`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
transferCache: localVarTransferCache,
reportProgress: reportProgress
}
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Helios API
*
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { HttpHeaders } from '@angular/common/http';

import { Observable } from 'rxjs';

import { BranchInfoDTO } from '../model/models';


import { Configuration } from '../configuration';



export interface BranchControllerServiceInterface {
defaultHeaders: HttpHeaders;
configuration: Configuration;

/**
*
*
*/
getAllBranches(extraHttpRequestParams?: any): Observable<Array<BranchInfoDTO>>;

}
17 changes: 17 additions & 0 deletions client/src/app/core/modules/openapi/model/branch-info-dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Helios API
*
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { RepositoryInfoDTO } from './repository-info-dto';


export interface BranchInfoDTO {
name: string;
repository?: RepositoryInfoDTO;
}

1 change: 1 addition & 0 deletions client/src/app/core/modules/openapi/model/models.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './branch-info-dto';
export * from './pull-request-info-dto';
export * from './repository-info-dto';
export * from './user-info-dto';
23 changes: 23 additions & 0 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/PullRequestInfoDTO"
/api/branches:
get:
tags:
- branch-controller
operationId: getAllBranches
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/BranchInfoDTO"
components:
schemas:
PullRequestInfoDTO:
Expand Down Expand Up @@ -161,3 +175,12 @@ components:
type: string
htmlUrl:
type: string
BranchInfoDTO:
required:
- name
type: object
properties:
name:
type: string
repository:
$ref: "#/components/schemas/RepositoryInfoDTO"
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package de.tum.cit.aet.helios.branch;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.time.OffsetDateTime;

import com.fasterxml.jackson.annotation.JsonProperty;

import de.tum.cit.aet.helios.gitrepo.GitRepository;
import de.tum.cit.aet.helios.user.User;

@Entity
@IdClass(BranchId.class)
@Getter
@Setter
@NoArgsConstructor
@ToString(callSuper = true)
public class Branch {

@Id
private String name;

@Id
@ManyToOne
@JoinColumn(name = "repository_id", nullable = false)
@ToString.Exclude
private GitRepository repository;

private String commit_sha;

@JsonProperty("protected")
private boolean protection;

private OffsetDateTime createdAt;

private OffsetDateTime updatedAt;

public void forEach(Object object) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'forEach'");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package de.tum.cit.aet.helios.branch;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/branches")
public class BranchController {

private final BranchService branchService;

public BranchController(BranchService branchService) {
this.branchService = branchService;
}

@GetMapping
public ResponseEntity<List<BranchInfoDTO>> getAllBranches() {
List<BranchInfoDTO> branches = branchService.getAllBranches();
return ResponseEntity.ok(branches);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.tum.cit.aet.helios.branch;

import java.io.Serializable;
import java.util.Objects;

public class BranchId implements Serializable {
private String name;
private Long repository;

// Default constructor
public BranchId() {}

public BranchId(String name, Long repository) {
this.name = name;
this.repository = repository;
}

// Equals and hashCode
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BranchId branchId = (BranchId) o;
return Objects.equals(name, branchId.name) &&
Objects.equals(repository, branchId.repository);
}

@Override
public int hashCode() {
return Objects.hash(name, repository);
}
}
Loading
Loading