-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(server): Github Branches Webhook & Rest & Controller (#65)
Co-authored-by: Stefan Nemeth <[email protected]>
- Loading branch information
1 parent
fb8cd49
commit b12d4c7
Showing
19 changed files
with
685 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
155
client/src/app/core/modules/openapi/api/branch-controller.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
client/src/app/core/modules/openapi/api/branch-controller.serviceInterface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
client/src/app/core/modules/openapi/model/branch-info-dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
server/application-server/src/main/java/de/tum/cit/aet/helios/branch/Branch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'"); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.