Skip to content

Commit

Permalink
ADM-675:[backend]: add cache for buildKite&GitHub&holiday feign client (
Browse files Browse the repository at this point in the history
  • Loading branch information
sqsq5566 authored Jan 11, 2024
2 parents ed736db + 8551490 commit ca482f0
Show file tree
Hide file tree
Showing 46 changed files with 150 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.List;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -21,14 +22,17 @@
@FeignClient(name = "buildKiteFeignClient", url = "${buildKite.url}", configuration = BuildKiteFeignClientDecoder.class)
public interface BuildKiteFeignClient {

@Cacheable(cacheNames = "tokenInfo", key = "#token")
@GetMapping(path = "v2/access-token")
@ResponseStatus(HttpStatus.OK)
BuildKiteTokenInfo getTokenInfo(@RequestHeader("Authorization") String token);

@Cacheable(cacheNames = "buildKiteOrganizationInfo", key = "#token")
@GetMapping(path = "v2/organizations")
@ResponseStatus(HttpStatus.OK)
List<BuildKiteOrganizationsInfo> getBuildKiteOrganizationsInfo(@RequestHeader("Authorization") String token);

@Cacheable(cacheNames = "pipelineInfo", key = "#organizationId+'-'+#page+'-'+#perPage+'-'+#startTime+'-'+#endTime")
@GetMapping(path = "v2/organizations/{organizationId}/pipelines?page={page}&per_page={perPage}")
@ResponseStatus(HttpStatus.OK)
List<BuildKitePipelineDTO> getPipelineInfo(@RequestHeader("Authorization") String token,
Expand All @@ -43,6 +47,9 @@ ResponseEntity<List<BuildKiteBuildInfo>> getPipelineSteps(@RequestHeader("Author
@RequestParam("per_page") String perPage, @RequestParam("created_from") String createdFrom,
@RequestParam("created_to") String createdTo, @RequestParam("branch[]") List<String> branch);

@Cacheable(cacheNames = "pipelineStepsInfo",
key = "#organizationId+'-'+#pipelineId+'-'+#page+'-'+#perPage+'-'"
+ "+#createdFrom+'-'+#createdTo+'-'+(#branch!=null ? branch.toString() : '')")
@GetMapping(path = "v2/organizations/{organizationId}/pipelines/{pipelineId}/builds",
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ResponseStatus(HttpStatus.OK)
Expand Down
7 changes: 7 additions & 0 deletions backend/src/main/java/heartbeat/client/GitHubFeignClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import heartbeat.client.dto.codebase.github.GitHubRepo;
import heartbeat.client.dto.codebase.github.PullRequestInfo;
import heartbeat.decoder.GitHubFeignClientDecoder;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -24,32 +25,38 @@ public interface GitHubFeignClient {
void verifyCanReadTargetBranch(@PathVariable String repository, @PathVariable String branchName,
@RequestHeader("Authorization") String token);

@Cacheable(cacheNames = "githubOrganizationInfo", key = "#token")
@GetMapping(path = "/user/orgs")
@ResponseStatus(HttpStatus.OK)
@Deprecated
List<GitHubOrganizationsInfo> getGithubOrganizationsInfo(@RequestHeader("Authorization") String token);

@Cacheable(cacheNames = "githubAllRepos", key = "#token")
@GetMapping(path = "/user/repos")
@ResponseStatus(HttpStatus.OK)
@Deprecated
List<GitHubRepo> getAllRepos(@RequestHeader("Authorization") String token);

@Cacheable(cacheNames = "githubRepos", key = "#organizationName")
@GetMapping(path = "/orgs/{organizationName}/repos")
@ResponseStatus(HttpStatus.OK)
@Deprecated
List<GitHubRepo> getReposByOrganizationName(@PathVariable String organizationName,
@RequestHeader("Authorization") String token);

@Cacheable(cacheNames = "commitInfo", key = "#repository+'-'+#commitId")
@GetMapping(path = "/repos/{repository}/commits/{commitId}")
@ResponseStatus(HttpStatus.OK)
CommitInfo getCommitInfo(@PathVariable String repository, @PathVariable String commitId,
@RequestHeader("Authorization") String token);

@Cacheable(cacheNames = "pullRequestCommitInfo", key = "#repository+'-'+#mergedPullNumber")
@GetMapping(path = "/repos/{repository}/pulls/{mergedPullNumber}/commits")
@ResponseStatus(HttpStatus.OK)
List<CommitInfo> getPullRequestCommitInfo(@PathVariable String repository, @PathVariable String mergedPullNumber,
@RequestHeader("Authorization") String token);

@Cacheable(cacheNames = "pullRequestListInfo", key = "#repository+'-'+#deployId")
@GetMapping(path = "/repos/{repository}/commits/{deployId}/pulls")
@ResponseStatus(HttpStatus.OK)
List<PullRequestInfo> getPullRequestListInfo(@PathVariable String repository, @PathVariable String deployId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import heartbeat.client.dto.board.jira.HolidaysResponseDTO;
import heartbeat.config.HolidayFeignClientConfiguration;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -10,6 +11,7 @@
configuration = HolidayFeignClientConfiguration.class)
public interface HolidayFeignClient {

@Cacheable(cacheNames = "holidayResult", key = "#year")
@GetMapping(path = "/{year}.json")
HolidaysResponseDTO getHolidays(@PathVariable String year);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ JiraBoardConfigDTO getJiraBoardConfiguration(URI baseUrl, @PathVariable String b
StatusSelfDTO getColumnStatusCategory(URI baseUrl, @PathVariable String statusNum,
@RequestHeader String authorization);

@Cacheable(cacheNames = "jiraCards", key = "#boardId+'-'+#queryCount+'-'+#startAt+'-'+#jql")
@GetMapping(path = "/rest/agile/1.0/board/{boardId}/issue?maxResults={queryCount}&startAt={startAt}&jql={jql}")
String getJiraCards(URI baseUrl, @PathVariable String boardId, @PathVariable int queryCount,
@PathVariable int startAt, @PathVariable String jql, @RequestHeader String authorization);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class HolidayDTO {
public class HolidayDTO implements Serializable {

private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class HolidaysResponseDTO {
public class HolidaysResponseDTO implements Serializable {

private List<HolidayDTO> days;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Author {
public class Author implements Serializable {

private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AuthorOuter {
public class AuthorOuter implements Serializable {

private String login;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Base {
public class Base implements Serializable {

private String label;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Comment {
public class Comment implements Serializable {

private String href;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Commit {
public class Commit implements Serializable {

private Author author;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CommitInfo {
public class CommitInfo implements Serializable {

private String sha;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Commits {
public class Commits implements Serializable {

private String href;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Committer {
public class Committer implements Serializable {

private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CommitterOuter {
public class CommitterOuter implements Serializable {

private String login;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class File {
public class File implements Serializable {

private String sha;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
public class GitHubOrganizationsInfo {
public class GitHubOrganizationsInfo implements Serializable {

private String login;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
public class GitHubRepo {
public class GitHubRepo implements Serializable {

@JsonProperty("html_url")
private String htmlUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Head {
public class Head implements Serializable {

private String label;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Html {
public class Html implements Serializable {

private String href;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Issue {
public class Issue implements Serializable {

private String href;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class License {
public class License implements Serializable {

private String key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class LinkCollection {
public class LinkCollection implements Serializable {

private Self self;

Expand Down
Loading

0 comments on commit ca482f0

Please sign in to comment.