Skip to content

Commit

Permalink
ADM-919[backend] : Speed up the generating of pipeline data in report…
Browse files Browse the repository at this point in the history
… page and add foru column in csv (#1361)

* ADM-919:[backend] feat: Speed up the generating of pipeline data in report page

* ADM-919:[backend] feat: fix e2e test

* fix(e2e): fix env

* Adm 920[backend] feat: Support to retrieve multiple pages of pipelines in metrics page (#1359)

* ADM-920:[backend] feat: can get all pipeline info

* ADM-920:[backend] fix: change Cache type

* ADM-873:[frontend]fix: fix notification logic (#1356)

Co-authored-by: yulongcai <141199398+yulongcai@users.noreply.github.com>

* ADM-898[backend][frontend]: feat: block' in board mapping is mutually exclusive with 'flag as block' (#1350)

* ADM-898:[backend] feat: should not export cycle time flag on table header when not consider flag as block

* ADM-898:[frontend]feat: not show flagCard when board mapping table has ‘block’ column

* ADM-898:[frontend]feat: warning pop-up when conflict

* ADM-898:[frontend]refactor: refactor codes

* ADM-898:[frontend]refactor: remove fromFlag

* ADM-898:[frontend]feat: not show flagCard when board mapping table has ‘block’ column

* ADM-873-bug:[backend] feat: add test for as flag is block is false

* ADM-898:[frontend]feat: add status logic

* ADM-898:[frontend]refactor: refactor code

* ADM-898:[backend] fix: fix bug for not calculate flag block to cycle when consider flag as block

* ADM-886:[docs]docs: refactor chart API docs sequence diagram (#1339)

* ADM-886:[docs]docs: update chart API image size

* ADM-886:[docs]docs: update chart API docs content

* ADM-886:[docs]docs: refactor chart API docs

* ADM-886:[docs]docs: refactor chart API docs sequence diagram

* ADM 834 add frontend validation to board Id (#1338)

* ADM-834:[frontend]feat: fix rebase

* ADM-834:[backend]feat: added api for domain url check

* ADM-834:[backend]feat: add dashboard api for site check

* ADM-834:[backend]feat: added api for domain url check

* ADM-834:[frontend]fix: fix rebase

* ADM-834:[frontend]fix: add regex validation to board id

* ADM-834:[frontend]fix: fix lint

* ADM 751 [docs]docs: fix readme in board mappings part (#1334)

* ADM-751:[frontend]feat: add by status e2e test flow into import test

* ADM-751:[frontend]feat: add more flow in create test

* ADM-751:[frontend]feat: fix lint and refactor fixture file

* ADM-751:[frontend]feat: fix by state flow and add new test

* ADM-751:[frontend]feat: refactored file strcture and implemented new e2e test for cycle time status testing, just need to fix the data then

* ADM-751:[frontend]feat: rework the by status flow e2e test, remove unnecessary steps

* ADM-751:[frontend]feat: fix test flow again

* ADM-751:[frontend]feat: fix type check

* ADM-751:[frontend]feat: add status flow e2e test in import test

* ADM-751:[frontend]fix: fix lint

* ADM-882:[backend]feat: add import json file

* ADM-751:[frontend]fix: refactor code

* ADM-751:[frontend]fix: refactor code fix type

* ADM-751:[docs]docs: fix readme in board mappings

* ADM-751:[docs]docs: remove conflicted rework part

* ADM-751 refactor

---------

Co-authored-by: guzhongren <guzhongren@live.cn>

* chore(sbom): generate sbom when releasing (#1340)

* ADM-833:[frontend]feat:add e2e unhappy path scenarios  (#1328)

* ADM-833:[frontend]feat:add e2e unhappy path scenarios

ADM-833: [frontend] add e2e test scenarios

ADM-833: [frontend] fix: fix code style error

ADM-833: [frontend] feat: add unhappy path scenoria

ADM-833: [frontend] feat: optimize add and remove new pipeline,add unhappy path template

ADM-833: [frontend] feat: optimize remove new pipeline,unhappy path template

ADM-833: [frontend] feat: optimize remove new pipeline,unhappy path template

ADM-833:[frontend]feat:merge unhappy path scenario

ADM-833: [frontend] update: update  e2e test scenarios

ADM-833: [frontend] fix: fix code style error

ADM-833: [frontend] update: update  e2e test scenarios

ADM-833: [frontend] update: update  e2e test scenarios

ADM-833: [frontend] fix: fix e2e test error

ADM-833:[frontend]feat:distinguish major and unhappy path test in local environment

ADM-833: [frontend] feat: sperate major and all

ADM-833[frontend]feat:change branch invalid error message

ADM-833: [frontend] fix: fix index.ts error

ADM-833: [frontend] fix: remove the log file

ADM-833: [frontend] fix: fix conflict with main branch

ADM-833: [frontend] fix: revert readme

ADM-833: [frontend] fix: remove log file

ADM-833: [frontend] fix: modify .gitignore, add omit logs

* ADM-833 fix path

* ADM-833: [frontend] fix: update the spec location

* ADM-833: [frontend] fix: fix daterange error

* ADM-833: [frontend] fix: fix review error

* ADM-833: [frontend] fix: fix review error

---------

Co-authored-by: YaoZhang-Daniel <zyao1987@163.com>
Co-authored-by: guzhongren <guzhongren@live.cn>

* ADM-833: [frontend] fix: fix env error (#1341)

* ADM-833:[frontend]feat:add e2e unhappy path scenarios

ADM-833: [frontend] add e2e test scenarios

ADM-833: [frontend] fix: fix code style error

ADM-833: [frontend] feat: add unhappy path scenoria

ADM-833: [frontend] feat: optimize add and remove new pipeline,add unhappy path template

ADM-833: [frontend] feat: optimize remove new pipeline,unhappy path template

ADM-833: [frontend] feat: optimize remove new pipeline,unhappy path template

ADM-833:[frontend]feat:merge unhappy path scenario

ADM-833: [frontend] update: update  e2e test scenarios

ADM-833: [frontend] fix: fix code style error

ADM-833: [frontend] update: update  e2e test scenarios

ADM-833: [frontend] update: update  e2e test scenarios

ADM-833: [frontend] fix: fix e2e test error

ADM-833:[frontend]feat:distinguish major and unhappy path test in local environment

ADM-833: [frontend] feat: sperate major and all

ADM-833[frontend]feat:change branch invalid error message

ADM-833: [frontend] fix: fix index.ts error

ADM-833: [frontend] fix: remove the log file

ADM-833: [frontend] fix: fix conflict with main branch

ADM-833: [frontend] fix: revert readme

ADM-833: [frontend] fix: remove log file

ADM-833: [frontend] fix: modify .gitignore, add omit logs

* ADM-833 fix path

* ADM-833: [frontend] fix: update the spec location

* ADM-833: [frontend] fix: fix daterange error

* ADM-833: [frontend] fix: fix review error

* ADM-833: [frontend] fix: fix review error

* ADM-833: [frontend] fix: fix env error

---------

Co-authored-by: YaoZhang-Daniel <zyao1987@163.com>
Co-authored-by: guzhongren <guzhongren@live.cn>

* Revert "ADM-833: [frontend] fix: fix env error (#1341)" (#1344)

This reverts commit eed90dc.

* [ADM-833][frontend]: chore: fix the e2e env injection error. (#1345)

* refactor(e2e): name conversion[frontend]

* fix(e2e): fix type check[frontend]

* ADM-898:[frontend]fix: fix test

* ADM-898:[frontend]feat: add test for CycleTime

* ADM-898:[frontend]fix: fix UpperCase error

* ADM-898:[frontend]fix: fix default value

* ADM-898:[frontend]fix: fix import treatFlagCardAsBlock value

* ADM-898:[backend] fix: repair e2e test

* ADM-898:[backend] fix: repair e2e test to delete check consider flag as block

* ADM-898:[backend] fix: sonar issue

* [ADM-877][frontend]: feat: remove the limit of start-date & end-date selection. (#1342)

* [ADM-877][frontend]: feat: remove the limit of start-date & end-date selection.

* [ADM-877][frontend]: chore: refine code.

* ADM-873:[frontend][backend] fix: fix success notification (#1327)

* ADM-873-bug:[docx] docx: fix docx

* ADM-873:[frontend]fix: fix error notification

* ADM-873:[frontend]refactor: refactor code

* ADM-873-bug:[backend] feat: return flag for whether it has file create by this invoke

* Revert "ADM-873:[frontend]refactor: refactor code"

This reverts commit e2fe52f.

* Revert "ADM-873:[frontend]fix: fix error notification"

This reverts commit b659c63.

* ADM-873:[frontend]fix: use hasCsvFileCreateSuccessful to handle success notification

* ADM-873-bug:[backend] feat: return has csv create successful when get completed

* ADM-873-bug:[backend] fix: rename

* ADM-873:[frontend]fix: fix test

* ADM-873:[frontend]refactor: rename hasCsvFileCreateSuccessful to isSuccessfulCreateCsvFile

* ADM-873:[backend]refactor: modify test info

* ADM-873:[backend]refactor: format code

---------

Co-authored-by: yulongcai <yulong.cai@thoughtworks.com>
Co-authored-by: Rui7ing <129819182+Rui7ing@users.noreply.github.com>

* [frontend] feat/adm 811: Do not clear the configuration settings when returning from the metric page to the configuration page. (#1343)

* [feat][adm-811]: remove GoCD option

* [frontend][adm-811]: feat: remove clear config data trigger when back to config page

* [frontend][adm-811]: refact: refact unit test

* [frontend][adm-811]: replace fireEvent use userEvent

* [frontend][adm-811]: fix failed case

* Adm 910[docs] feat: add Github graghQL rate limit issue (#1348)

* ADM-910[docs] feat: add Node and Rate limits and calculate

* ADM-910[docs] feat: add flew chart for get data by github api

* Adm 912[frontend]: ui refine date picker in metrics page (#1349)

* ADM-912 feat: display date ranges

* ADM-912 test: add unit test

* ADM-912 fix: fix css

* ADM-912 fix: fix color

* ADM-912 fix: fix hex color

* ADM-912 fix: use color from theme

* ADM-898:[frontend]feat: add block case

* ADM-898:[frontend]fix: fix test for treatFlagCardAsBlock

* ADM-898:[frontend]fix: fix bug

* ADM-898 fix: fix treat flag card as block when import

* ADM-898 fix: fix treat flag card as block when create

* ADM-898 refactor: rename

* ADM-898:[frontend]fix: remove unnecessary cycleTimeSettings

* ADM-898 fix: fix test

* ADM-898:[backend] refactor: refactor code

* ADM-898 test: add unit test

* ADM-898 test: add e2e test for no block column board when create project

* ADM-898 test: add e2e test for no block column board when import project

* ADM-898:[frontend]refactor: iterate over test data and run tests using forEach

* ADM-898:[frontend]refactor: export BLOCK_COLUMN_NAME

* ADM-898:[frontend]refactor: fix prettier error

* ADM-898:[frontend]fix: fix the error from merge

---------

Co-authored-by: Tingyu Dong <tingyu.dong@thoughtworks.com>
Co-authored-by: Steveay <907221539@qq.com>
Co-authored-by: PengxiWPix <113176309+PengxiWPix@users.noreply.github.com>
Co-authored-by: guzhongren <guzhongren@live.cn>
Co-authored-by: YaoZhang87 <162096287+YaoZhang87@users.noreply.github.com>
Co-authored-by: YaoZhang-Daniel <zyao1987@163.com>
Co-authored-by: Chao <89126516+mrcuriosity-tw@users.noreply.github.com>
Co-authored-by: TingyuDong <113588395+TingyuDong@users.noreply.github.com>
Co-authored-by: Rui7ing <129819182+Rui7ing@users.noreply.github.com>
Co-authored-by: K Chow <kai.zhou@thoughtworks.com>
Co-authored-by: junbo dai <junbo.dai@thoughtworks.com>
Co-authored-by: Leiqiuhong <141199516+Leiqiuhong@users.noreply.github.com>
Co-authored-by: Leiqiuhong <qiuhong.lei@thoughtworks.com>

* ADM-919:[backend] feat: add revert column in csv

* ADM-919:[backend] feat: add job start time and pipeline start time and no pr commit time in csv

* ADM-919:[backend] feat: fix e2e expect csv

* ADM-919:[backend] feat: fix sonar error

* ADM-919:[backend] fix: delete no use code

* ADM-919:[backend] fix: add test for when build kite data info have author

* ADM-919:[backend] fix: fix sonar error for eq

* ADM-919:[backend] fix: update check error

* ADM-919:[backend] fix: repair sonar issue

* ADM-919:[backend] fix: format code

* ADM-919:[backend] fix: add Nullable for field

---------

Co-authored-by: guzhongren <guzhongren@live.cn>
Co-authored-by: junbo dai <junbo.dai@thoughtworks.com>
Co-authored-by: TingyuDong <113588395+TingyuDong@users.noreply.github.com>
Co-authored-by: Tingyu Dong <tingyu.dong@thoughtworks.com>
Co-authored-by: Steveay <907221539@qq.com>
Co-authored-by: PengxiWPix <113176309+PengxiWPix@users.noreply.github.com>
Co-authored-by: YaoZhang87 <162096287+YaoZhang87@users.noreply.github.com>
Co-authored-by: YaoZhang-Daniel <zyao1987@163.com>
Co-authored-by: Chao <89126516+mrcuriosity-tw@users.noreply.github.com>
Co-authored-by: Rui7ing <129819182+Rui7ing@users.noreply.github.com>
Co-authored-by: K Chow <kai.zhou@thoughtworks.com>
Co-authored-by: Leiqiuhong <141199516+Leiqiuhong@users.noreply.github.com>
Co-authored-by: Leiqiuhong <qiuhong.lei@thoughtworks.com>
  • Loading branch information
14 people authored Apr 12, 2024
1 parent 7d7e852 commit 6b43c85
Show file tree
Hide file tree
Showing 12 changed files with 537 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ public class LeadTime {

private long jobFinishTime;

private long jobStartTime;

@Nullable
private Long noPRCommitTime;

@Nullable
private Long firstCommitTime;

private long pipelineCreateTime;

@Nullable
private Boolean isRevert;

@Nullable
private Long prLeadTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public class LeadTimeInfo {

private String jobFinishTime;

private String jobStartTime;

private String noPRCommitTime;

private String firstCommitTime;

@Nullable
private String prLeadTime;

Expand All @@ -33,33 +39,34 @@ public class LeadTimeInfo {
@Nullable
private String totalTime;

public LeadTimeInfo(LeadTime leadTime) {
if (leadTime != null) {
if (leadTime.getFirstCommitTimeInPr() != null) {
this.firstCommitTimeInPr = TimeUtil
.convertToISOFormat(String.valueOf(leadTime.getFirstCommitTimeInPr()));
}

if (leadTime.getPrCreatedTime() != null) {
this.prCreatedTime = TimeUtil.convertToISOFormat(String.valueOf(leadTime.getPrCreatedTime()));
}

if (leadTime.getPrMergedTime() != null) {
this.prMergedTime = TimeUtil.convertToISOFormat(String.valueOf(leadTime.getPrMergedTime()));
}

this.jobFinishTime = TimeUtil.convertToISOFormat(String.valueOf(leadTime.getJobFinishTime()));
private Boolean isRevert;

this.pipelineLeadTime = TimeUtil.msToHMS(leadTime.getPipelineLeadTime());

if (leadTime.getPrLeadTime() != null) {
this.prLeadTime = TimeUtil.msToHMS(leadTime.getPrLeadTime());
}
public LeadTimeInfo(LeadTime leadTime) {
if (leadTime == null) {
return;
}
this.firstCommitTimeInPr = convertToISOFormat(leadTime.getFirstCommitTimeInPr());
this.prCreatedTime = convertToISOFormat(leadTime.getPrCreatedTime());
this.prMergedTime = convertToISOFormat(leadTime.getPrMergedTime());
this.jobFinishTime = convertToISOFormat(leadTime.getJobFinishTime());
this.jobStartTime = convertToISOFormat(leadTime.getJobStartTime());
this.firstCommitTime = convertToISOFormat(leadTime.getFirstCommitTime());
this.noPRCommitTime = convertToISOFormat(leadTime.getNoPRCommitTime());

this.pipelineLeadTime = TimeUtil.msToHMS(leadTime.getPipelineLeadTime());
this.isRevert = leadTime.getIsRevert();

if (leadTime.getPrLeadTime() != null) {
this.prLeadTime = TimeUtil.msToHMS(leadTime.getPrLeadTime());
}

if (leadTime.getTotalTime() != 0) {
this.totalTime = TimeUtil.msToHMS(leadTime.getTotalTime());
}
if (leadTime.getTotalTime() != 0) {
this.totalTime = TimeUtil.msToHMS(leadTime.getTotalTime());
}
}

private String convertToISOFormat(Long time) {
return time != null ? TimeUtil.convertToISOFormat(String.valueOf(time)) : null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -101,9 +99,10 @@ public void convertPipelineDataToCSV(List<PipelineCSVInfo> leadTimeData, String
File file = new File(fileName);
try (CSVWriter csvWriter = new CSVWriter(new FileWriter(file))) {
String[] headers = { "Organization", "Pipeline Name", "Pipeline Step", "Valid", "Build Number",
"Code Committer", "Pipeline Creator", "First Code Committed Time In PR", "Code Committed Time",
"PR Created Time", "PR Merged Time", "Deployment Completed Time", "Total Lead Time (HH:mm:ss)",
"PR Lead Time (HH:mm:ss)", "Pipeline Lead Time (HH:mm:ss)", "Status", "Branch" };
"Code Committer", "Pipeline Creator", "First Code Committed Time In PR", "PR Created Time",
"PR Merged Time", "No PR Committed Time", "Job Start Time", "Pipeline Start Time",
"Pipeline Finish Time", "Total Lead Time (HH:mm:ss)", "PR Lead Time (HH:mm:ss)",
"Pipeline Lead Time (HH:mm:ss)", "Status", "Branch", "Revert" };

csvWriter.writeNext(headers);

Expand All @@ -120,23 +119,21 @@ public void convertPipelineDataToCSV(List<PipelineCSVInfo> leadTimeData, String
}

private String[] getRowData(PipelineCSVInfo csvInfo) {
String committerName = null;
String commitDate = null;
if (csvInfo.getCommitInfo() != null) {
committerName = csvInfo.getCommitInfo().getCommit().getAuthor().getName();
commitDate = csvInfo.getCommitInfo().getCommit().getAuthor().getDate();
}

String creatorName = null;
if (csvInfo.getBuildInfo().getCreator() != null && csvInfo.getBuildInfo().getCreator().getName() != null) {
creatorName = csvInfo.getBuildInfo().getCreator().getName();
}
String committerName = null;
if (csvInfo.getBuildInfo().getAuthor() != null && csvInfo.getBuildInfo().getAuthor().getName() != null) {
committerName = String.valueOf(csvInfo.getBuildInfo().getAuthor().getName());
}

String organization = csvInfo.getOrganizationName();
String pipelineName = csvInfo.getPipeLineName();
String stepName = csvInfo.getStepName();
String valid = String.valueOf(csvInfo.getValid()).toLowerCase();
String buildNumber = String.valueOf(csvInfo.getBuildInfo().getNumber());

String state = csvInfo.getPiplineStatus().equals(CANCELED_STATUS) ? CANCELED_STATUS
: csvInfo.getDeployInfo().getState();
String branch = csvInfo.getBuildInfo().getBranch();
Expand All @@ -145,14 +142,18 @@ private String[] getRowData(PipelineCSVInfo csvInfo) {
String firstCommitTimeInPr = leadTimeInfo.getFirstCommitTimeInPr();
String prCreatedTime = leadTimeInfo.getPrCreatedTime();
String prMergedTime = leadTimeInfo.getPrMergedTime();
String jobFinishTime = csvInfo.getDeployInfo().getJobFinishTime();
String noPRCommitTime = leadTimeInfo.getNoPRCommitTime();
String jobStartTime = leadTimeInfo.getJobStartTime();
String pipelineStartTime = leadTimeInfo.getFirstCommitTime();
String pipelineFinishTime = csvInfo.getDeployInfo().getJobFinishTime();
String totalTime = leadTimeInfo.getTotalTime();
String prLeadTime = leadTimeInfo.getPrLeadTime();
String pipelineLeadTime = leadTimeInfo.getPipelineLeadTime();
String isRevert = leadTimeInfo.getIsRevert() == null ? "" : String.valueOf(leadTimeInfo.getIsRevert());

return new String[] { organization, pipelineName, stepName, valid, buildNumber, committerName, creatorName,
firstCommitTimeInPr, commitDate, prCreatedTime, prMergedTime, jobFinishTime, totalTime, prLeadTime,
pipelineLeadTime, state, branch };
firstCommitTimeInPr, prCreatedTime, prMergedTime, noPRCommitTime, jobStartTime, pipelineStartTime,
pipelineFinishTime, totalTime, prLeadTime, pipelineLeadTime, state, branch, isRevert };
}

public InputStreamResource getDataFromCSV(ReportType reportDataType, long csvTimeStamp) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package heartbeat.service.report;

import heartbeat.client.dto.codebase.github.Author;
import heartbeat.client.dto.codebase.github.CommitInfo;
import heartbeat.client.dto.codebase.github.LeadTime;
import heartbeat.client.dto.codebase.github.PipelineLeadTime;
Expand Down Expand Up @@ -56,7 +57,7 @@ public FetchedData.BuildKiteData fetchBuildKiteInfo(GenerateReportRequest reques
String endTime = request.getEndTime();
FetchedData.BuildKiteData result = new FetchedData.BuildKiteData();

request.getBuildKiteSetting().getDeploymentEnvList().stream().forEach(deploymentEnvironment -> {
request.getBuildKiteSetting().getDeploymentEnvList().forEach(deploymentEnvironment -> {
List<BuildKiteBuildInfo> buildKiteBuildInfo = getBuildKiteBuildInfo(startTime, endTime,
deploymentEnvironment, request.getBuildKiteSetting().getToken(),
request.getBuildKiteSetting().getPipelineCrews());
Expand Down Expand Up @@ -97,12 +98,15 @@ private PipelineCSVInfo getPipelineCSVInfo(CodebaseSetting codebaseSetting, Stri
BuildKiteBuildInfo buildInfo, List<String> pipelineSteps) {
DeployInfo deployInfo = buildKiteService.mapToDeployInfo(buildInfo, pipelineSteps, REQUIRED_STATES, startTime,
endTime);
CommitInfo commitInfo = null;
if (Objects.nonNull(codebaseSetting) && StringUtils.hasLength(codebaseSetting.getToken())
&& Objects.nonNull(deployInfo.getCommitId())) {
commitInfo = gitHubService.fetchCommitInfo(deployInfo.getCommitId(),
&& Objects.nonNull(deployInfo.getCommitId()) && Objects.isNull(buildInfo.getAuthor())) {
CommitInfo commitInfo = gitHubService.fetchCommitInfo(deployInfo.getCommitId(),
GithubUtil.getGithubUrlFullName(deploymentEnvironment.getRepository()), codebaseSetting.getToken());
Author author = commitInfo.getCommit().getAuthor();
buildInfo
.setAuthor(BuildKiteBuildInfo.Author.builder().name(author.getName()).email(author.getEmail()).build());
}

return PipelineCSVInfo.builder()
.organizationName(deploymentEnvironment.getOrgName())
.pipeLineName(deploymentEnvironment.getName())
Expand All @@ -111,7 +115,6 @@ private PipelineCSVInfo getPipelineCSVInfo(CodebaseSetting codebaseSetting, Stri
.piplineStatus(buildInfo.getState())
.buildInfo(buildInfo)
.deployInfo(deployInfo)
.commitInfo(commitInfo)
.leadTimeInfo(new LeadTimeInfo(filterLeadTime(buildKiteData, deploymentEnvironment, deployInfo)))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,11 @@ private LeadTime parseNoMergeLeadTime(DeployInfo deployInfo, PipelineInfoOfRepos
deployInfo.getCommitId(), e.getMessage());
}

Long noPRCommitTime = null;
if (commitInfo.getCommit() != null && commitInfo.getCommit().getCommitter() != null
&& commitInfo.getCommit().getCommitter().getDate() != null) {
firstCommitTime = Instant.parse(commitInfo.getCommit().getCommitter().getDate()).toEpochMilli();
noPRCommitTime = Instant.parse(commitInfo.getCommit().getCommitter().getDate()).toEpochMilli();
firstCommitTime = noPRCommitTime;
}
else {
firstCommitTime = jobStartTime;
Expand All @@ -217,19 +219,32 @@ private LeadTime parseNoMergeLeadTime(DeployInfo deployInfo, PipelineInfoOfRepos
.commitId(deployInfo.getCommitId())
.pipelineCreateTime(pipelineCreateTime)
.jobFinishTime(jobFinishTime)
.jobStartTime(jobStartTime)
.noPRCommitTime(noPRCommitTime)
.firstCommitTime(firstCommitTime)
.pipelineLeadTime(jobFinishTime - firstCommitTime)
.totalTime(jobFinishTime - firstCommitTime)
.prLeadTime(prLeadTime)
.isRevert(isRevert(commitInfo))
.build();
}

private Boolean isRevert(CommitInfo commitInfo) {
Boolean isRevert = null;
if (commitInfo.getCommit() != null && commitInfo.getCommit().getMessage() != null) {
isRevert = commitInfo.getCommit().getMessage().toLowerCase().startsWith("revert");
}
return isRevert;
}

public LeadTime mapLeadTimeWithInfo(PullRequestInfo pullRequestInfo, DeployInfo deployInfo, CommitInfo commitInfo) {
if (pullRequestInfo.getMergedAt() == null) {
return null;
}
long prCreatedTime = Instant.parse(pullRequestInfo.getCreatedAt()).toEpochMilli();
long prMergedTime = Instant.parse(pullRequestInfo.getMergedAt()).toEpochMilli();
long jobFinishTime = Instant.parse(deployInfo.getJobFinishTime()).toEpochMilli();
long jobStartTime = Instant.parse(deployInfo.getJobStartTime()).toEpochMilli();
long pipelineCreateTime = Instant.parse(deployInfo.getPipelineCreateTime()).toEpochMilli();
long firstCommitTimeInPr;
if (commitInfo.getCommit() != null && commitInfo.getCommit().getCommitter() != null
Expand All @@ -243,16 +258,12 @@ public LeadTime mapLeadTimeWithInfo(PullRequestInfo pullRequestInfo, DeployInfo
long pipelineLeadTime = jobFinishTime - prMergedTime;
long prLeadTime;
long totalTime;
if (commitInfo.getCommit().getMessage().toLowerCase().startsWith("revert")) {
Boolean isRevert = isRevert(commitInfo);
if (Boolean.TRUE.equals(isRevert) || isNoFirstCommitTimeInPr(firstCommitTimeInPr)) {
prLeadTime = 0;
}
else {
if (firstCommitTimeInPr > 0) {
prLeadTime = prMergedTime - firstCommitTimeInPr;
}
else {
prLeadTime = prMergedTime - prCreatedTime;
}
prLeadTime = prMergedTime - firstCommitTimeInPr;
}
totalTime = prLeadTime + pipelineLeadTime;

Expand All @@ -265,10 +276,17 @@ public LeadTime mapLeadTimeWithInfo(PullRequestInfo pullRequestInfo, DeployInfo
.prCreatedTime(prCreatedTime)
.commitId(deployInfo.getCommitId())
.jobFinishTime(jobFinishTime)
.jobStartTime(jobStartTime)
.firstCommitTime(prMergedTime)
.pipelineCreateTime(pipelineCreateTime)
.isRevert(isRevert)
.build();
}

private static boolean isNoFirstCommitTimeInPr(long firstCommitTimeInPr) {
return firstCommitTimeInPr == 0;
}

public CommitInfo fetchCommitInfo(String commitId, String repositoryId, String token) {
try {
String realToken = BEARER_TITLE + token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ public class LeadTimeInfoTest {
@Test
void shouldCreateLeadTimeInfoWithLeadTime() {
LeadTimeInfo info = new LeadTimeInfo(LeadTime.builder()
.prLeadTime(47255635l)
.firstCommitTimeInPr(1672556350000l)
.prCreatedTime(1706067997l)
.prMergedTime(1706067997l)
.totalTime(57255635l)
.prLeadTime(47255635L)
.firstCommitTimeInPr(1672556350000L)
.prCreatedTime(1706067997L)
.prMergedTime(1706067997L)
.firstCommitTime(1706067997L)
.noPRCommitTime(1706067997L)
.totalTime(57255635L)
.isRevert(Boolean.FALSE)
.build());

assertEquals("13:7:35", info.getPrLeadTime());
assertEquals("2023-01-01T06:59:10Z", info.getFirstCommitTimeInPr());
assertEquals("1970-01-20T17:54:27Z", info.getPrMergedTime());
assertEquals("1970-01-20T17:54:27Z", info.getPrCreatedTime());
assertEquals("1970-01-20T17:54:27Z", info.getFirstCommitTime());
assertEquals("1970-01-20T17:54:27Z", info.getNoPRCommitTime());
assertEquals("15:54:15", info.getTotalTime());
assertEquals(Boolean.FALSE, info.getIsRevert());
}

}
Loading

0 comments on commit 6b43c85

Please sign in to comment.