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

ADM-1003 [frontend][backend][docs]: calculate pr lead time when source config #1599

Merged
merged 18 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions backend/src/main/java/heartbeat/client/GitHubFeignClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import heartbeat.client.dto.codebase.github.BranchesInfoDTO;
import heartbeat.client.dto.codebase.github.CommitInfo;
import heartbeat.client.dto.codebase.github.OrganizationsInfoDTO;
import heartbeat.client.dto.codebase.github.PullRequestInfo;

import heartbeat.client.dto.codebase.github.PullRequestInfoDTO;
import heartbeat.client.dto.codebase.github.PullRequestInfo;
import heartbeat.client.dto.codebase.github.ReposInfoDTO;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.openfeign.FeignClient;
Expand Down Expand Up @@ -66,7 +65,7 @@ ResponseEntity<List<BranchesInfoDTO>> getAllBranches(@RequestHeader("Authorizati

@GetMapping(path = "/repos/{org}/{repo}/pulls")
@ResponseStatus(HttpStatus.OK)
ResponseEntity<List<PullRequestInfoDTO>> getAllPullRequests(@RequestHeader("Authorization") String token,
ResponseEntity<List<PullRequestInfo>> getAllPullRequests(@RequestHeader("Authorization") String token,
@PathVariable("org") String org, @PathVariable("repo") String repo, @RequestParam("per_page") int perPage,
@RequestParam("page") int page, @RequestParam("base") String base, @RequestParam("state") String state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public class LeadTime {
@Nullable
private Long firstCommitTimeInPr;

private long jobFinishTime;
private Long jobFinishTime;

private long jobStartTime;
private Long jobStartTime;

@Nullable
private Long noPRCommitTime;

@Nullable
private Long firstCommitTime;

private long pipelineCreateTime;
private Long pipelineCreateTime;

@Nullable
private Boolean isRevert;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class PagePullRequestInfoDTO implements Serializable {
public class PagePullRequestInfo implements Serializable {

private int totalPage;

private List<PullRequestInfoDTO> pageInfo;
private List<PullRequestInfo> pageInfo;

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package heartbeat.client.dto.codebase.github;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -14,6 +16,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
public class PullRequestInfo implements Serializable {

private Integer number;
Expand All @@ -29,4 +32,17 @@ public class PullRequestInfo implements Serializable {
@JsonProperty("merge_commit_sha")
private String mergeCommitSha;

private PullRequestUser user;

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

private String login;

}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package heartbeat.client.dto.codebase.github;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SourceControlLeadTime {

private String organization;

private String repo;

private List<LeadTime> leadTimes;

}
5 changes: 2 additions & 3 deletions backend/src/main/java/heartbeat/config/CacheConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package heartbeat.config;

import heartbeat.client.dto.board.jira.CardHistoryResponseDTO;
import heartbeat.client.dto.board.jira.CalendarificHolidayResponseDTO;
import heartbeat.client.dto.board.jira.FieldResponseDTO;
import heartbeat.client.dto.board.jira.HolidaysResponseDTO;
import heartbeat.client.dto.board.jira.JiraBoardConfigDTO;
Expand All @@ -11,7 +10,7 @@
import heartbeat.client.dto.codebase.github.CommitInfo;
import heartbeat.client.dto.codebase.github.PageBranchesInfoDTO;
import heartbeat.client.dto.codebase.github.PageOrganizationsInfoDTO;
import heartbeat.client.dto.codebase.github.PagePullRequestInfoDTO;
import heartbeat.client.dto.codebase.github.PagePullRequestInfo;
import heartbeat.client.dto.codebase.github.PageReposInfoDTO;
import heartbeat.client.dto.pipeline.buildkite.BuildKiteTokenInfo;
import heartbeat.client.dto.pipeline.buildkite.PageBuildKitePipelineInfoDTO;
Expand Down Expand Up @@ -64,7 +63,7 @@ public CacheManager ehCacheManager() {
cacheManager.createCache("pageOrganization", getCacheConfiguration(PageOrganizationsInfoDTO.class));
cacheManager.createCache("pageRepo", getCacheConfiguration(PageReposInfoDTO.class));
cacheManager.createCache("pageBranch", getCacheConfiguration(PageBranchesInfoDTO.class));
cacheManager.createCache("pagePullRequest", getCacheConfiguration(PagePullRequestInfoDTO.class));
cacheManager.createCache("pagePullRequest", getCacheConfiguration(PagePullRequestInfo.class));
return cacheManager;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package heartbeat.controller.report.dto.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CodeBase {

private List<String> branches;

private String repo;

private String organization;

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public class CodebaseSetting {

private List<DeploymentEnvironment> leadTime;

private List<String> crews;

private List<CodeBase> codebases;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import heartbeat.client.dto.codebase.github.OrganizationsInfoDTO;
import heartbeat.client.dto.codebase.github.PageBranchesInfoDTO;
import heartbeat.client.dto.codebase.github.PageOrganizationsInfoDTO;
import heartbeat.client.dto.codebase.github.PagePullRequestInfoDTO;
import heartbeat.client.dto.codebase.github.PagePullRequestInfo;
import heartbeat.client.dto.codebase.github.PageReposInfoDTO;
import heartbeat.client.dto.codebase.github.PullRequestInfoDTO;
import heartbeat.client.dto.codebase.github.PullRequestInfo;
import heartbeat.client.dto.codebase.github.ReposInfoDTO;
import heartbeat.client.dto.pipeline.buildkite.BuildKiteBuildInfo;
import heartbeat.client.dto.pipeline.buildkite.PageBuildKitePipelineInfoDTO;
Expand Down Expand Up @@ -136,15 +136,15 @@ public PageBranchesInfoDTO getGitHubBranches(String token, String organization,

@Cacheable(cacheNames = "pagePullRequest",
key = "#token+'-'+#organization+'-'+#repo+'-'+#branch+'-'+#page+'-'+#perPage")
public PagePullRequestInfoDTO getGitHubPullRequest(String token, String organization, String repo, String branch,
public PagePullRequestInfo getGitHubPullRequest(String token, String organization, String repo, String branch,
int page, int perPage) {
try {
log.info("Start to get paginated github pull request info, page: {}", page);
ResponseEntity<List<PullRequestInfoDTO>> allPullRequests = gitHubFeignClient.getAllPullRequests(token,
ResponseEntity<List<PullRequestInfo>> allPullRequests = gitHubFeignClient.getAllPullRequests(token,
organization, repo, perPage, page, branch, "all");
log.info("Successfully get paginated github pull request info, page: {}", page);
int totalPage = parseTotalPage(allPullRequests.getHeaders().get(BUILD_KITE_LINK_HEADER));
return PagePullRequestInfoDTO.builder().pageInfo(allPullRequests.getBody()).totalPage(totalPage).build();
return PagePullRequestInfo.builder().pageInfo(allPullRequests.getBody()).totalPage(totalPage).build();
}
catch (BaseException e) {
log.info("Error to get paginated github pull request info, page: {}, exception: {}", page, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import heartbeat.service.report.calculator.model.FetchedData;
import heartbeat.service.report.calculator.model.FetchedData.BuildKiteData;
import heartbeat.repository.FileRepository;
import heartbeat.service.source.github.GitHubService;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections.CollectionUtils;
Expand Down Expand Up @@ -56,6 +57,8 @@ public class GenerateReporterService {

private final PipelineService pipelineService;

private final GitHubService gitHubService;

private final ClassificationCalculator classificationCalculator;

private final DeploymentFrequencyCalculator deploymentFrequency;
Expand Down Expand Up @@ -269,6 +272,7 @@ private void fetchGitHubData(GenerateReportRequest request, FetchedData fetchedD
if (request.getCodebaseSetting() == null)
throw new BadRequestException("Failed to fetch Github info due to code base setting is null.");
fetchedData.setBuildKiteData(pipelineService.fetchGitHubData(request));
fetchedData.setRepoData(gitHubService.fetchRepoData(request));
}

private FetchedData fetchJiraBoardData(GenerateReportRequest request, FetchedData fetchedData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package heartbeat.service.report.calculator.model;

import heartbeat.client.dto.codebase.github.PipelineLeadTime;
import heartbeat.client.dto.codebase.github.SourceControlLeadTime;
import heartbeat.client.dto.pipeline.buildkite.BuildKiteBuildInfo;
import heartbeat.client.dto.pipeline.buildkite.DeployTimes;
import heartbeat.controller.board.dto.response.CardCollection;
Expand All @@ -20,6 +21,8 @@ public class FetchedData {

private BuildKiteData buildKiteData;

private RepoData repoData;

@Data
@Builder
public static class CardCollectionInfo {
Expand Down Expand Up @@ -57,4 +60,13 @@ public void addBuildKiteBuildInfos(String key, List<BuildKiteBuildInfo> buildKit

}

@Data
@Builder
@AllArgsConstructor
public static class RepoData {

private List<SourceControlLeadTime> sourceControlLeadTimes;

}

}
Loading
Loading