Skip to content

Commit

Permalink
Merge branch 'main' into ADM-948
Browse files Browse the repository at this point in the history
  • Loading branch information
Leiqiuhong committed May 21, 2024
2 parents 4225bd9 + 1735d0d commit 35282c0
Show file tree
Hide file tree
Showing 41 changed files with 6,954 additions and 5,429 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ They are sharing the similar settings which you need to specify the pipeline ste
| Branches | Your selected branches |
| Crew setting | Your selected author from github |

##### 3.2.5.1 Crew setting

The data source of **crew setting** is Github code committer. Heartbeat will list distinct code committers for those builds of the selected periods. And the value of code committer is the GitHub username.

If builds were manually/scheduled triggered or could not find code committer from Github, Heartbeat will mark as "Unknown" in crew setting.

## 3.3 Export and import config info

### 3.3.1 Export Config Json File
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class BuildKiteBuildInfo implements Serializable {
@Builder
public static class Author implements Serializable {

private String userName;
private String username;

private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.IntStream;

import static java.util.Optional.ofNullable;

@Service
@RequiredArgsConstructor
@Log4j2
Expand Down Expand Up @@ -79,9 +80,11 @@ public List<String> getPipelineStepNames(List<BuildKiteBuildInfo> buildKiteBuild
}

public List<String> getPipelineCrewNames(List<BuildKiteBuildInfo> buildKiteBuildInfos) {

List<String> buildInfoList = new ArrayList<>(buildKiteBuildInfos.stream()
.filter(buildKiteBuildInfo -> Objects.nonNull(buildKiteBuildInfo.getAuthor()))
.map(buildKiteBuildInfo -> buildKiteBuildInfo.getAuthor().getName())
.map(BuildKiteBuildInfo::getAuthor)
.filter(Objects::nonNull)
.map(it -> ofNullable(it.getUsername()).orElse(it.getName()))
.distinct()
.sorted()
.toList());
Expand Down Expand Up @@ -129,7 +132,7 @@ public PipelineStepsDTO fetchPipelineSteps(String token, String organizationId,
.build();
}
catch (RuntimeException e) {
Throwable cause = Optional.ofNullable(e.getCause()).orElse(e);
Throwable cause = ofNullable(e.getCause()).orElse(e);
log.error("Failed to get pipeline steps, organization id: {}, pipeline id: {}, e: {}", organizationId,
pipelineId, cause.getMessage());
if (cause instanceof BaseException baseException) {
Expand Down Expand Up @@ -217,7 +220,7 @@ public List<BuildKiteBuildInfo> fetchPipelineBuilds(String token, DeploymentEnvi
return buildKiteBuildInfos;
}
catch (RuntimeException e) {
Throwable cause = Optional.ofNullable(e.getCause()).orElse(e);
Throwable cause = ofNullable(e.getCause()).orElse(e);
log.error("Failed to get pipeline builds_param:{}, e: {}", deploymentEnvironment, cause.getMessage());
if (cause instanceof BaseException baseException) {
throw baseException;
Expand Down Expand Up @@ -267,7 +270,7 @@ public void verifyToken(String token) {
verifyTokenScopes(buildKiteTokenInfo);
}
catch (RuntimeException e) {
Throwable cause = Optional.ofNullable(e.getCause()).orElse(e);
Throwable cause = ofNullable(e.getCause()).orElse(e);
log.error("Failed to call BuildKite, e: {}", cause.getMessage());
if (cause instanceof BaseException baseException) {
throw baseException;
Expand Down Expand Up @@ -297,7 +300,7 @@ public BuildKiteResponseDTO getBuildKiteInfo(TokenParam tokenParam) {
return BuildKiteResponseDTO.builder().pipelineList(buildKiteInfoList).build();
}
catch (RuntimeException e) {
Throwable cause = Optional.ofNullable(e.getCause()).orElse(e);
Throwable cause = ofNullable(e.getCause()).orElse(e);
log.error("Failed to call BuildKite, e: {}", cause.getMessage());
if (cause instanceof BaseException baseException) {
throw baseException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.opencsv.CSVWriter;
import heartbeat.client.dto.pipeline.buildkite.BuildKiteBuildInfo;
import heartbeat.controller.board.dto.response.JiraCardDTO;
import heartbeat.controller.report.dto.request.ReportType;
import heartbeat.controller.report.dto.response.AvgDeploymentFrequency;
Expand Down Expand Up @@ -53,6 +54,7 @@
import static heartbeat.service.report.calculator.ClassificationCalculator.pickDisplayNameFromObj;
import static heartbeat.util.DecimalUtil.formatDecimalFour;
import static heartbeat.util.TimeUtil.convertToSimpleISOFormat;
import static java.util.Optional.ofNullable;
import static java.util.concurrent.TimeUnit.HOURS;

@RequiredArgsConstructor
Expand Down Expand Up @@ -124,15 +126,12 @@ public void convertPipelineDataToCSV(List<PipelineCSVInfo> leadTimeData, String
}

private String[] getRowData(PipelineCSVInfo csvInfo) {
String committerName = null;
if (csvInfo.getBuildInfo().getAuthor() != null && csvInfo.getBuildInfo().getAuthor().getName() != null) {
committerName = String.valueOf(csvInfo.getBuildInfo().getAuthor().getName());
}
String committerName = ofNullable(csvInfo.getBuildInfo().getAuthor())
.map(BuildKiteBuildInfo.Author::getUsername)
.orElse(null);

String creatorName = null;
if (csvInfo.getBuildInfo().getCreator() != null && csvInfo.getBuildInfo().getCreator().getName() != null) {
creatorName = csvInfo.getBuildInfo().getCreator().getName();
}
String creatorName = ofNullable(csvInfo.getBuildInfo().getCreator()).map(BuildKiteBuildInfo.Creator::getName)
.orElse(null);

String organization = csvInfo.getOrganizationName();
String pipelineName = csvInfo.getPipeLineName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,26 @@ private Map<String, String> getRepoMap(List<DeploymentEnvironment> deploymentEnv

private List<BuildKiteBuildInfo> getBuildKiteBuildInfo(String startTime, String endTime,
DeploymentEnvironment deploymentEnvironment, String token, List<String> pipelineCrews) {
List<BuildKiteBuildInfo> buildKiteBuildInfo = buildKiteService.fetchPipelineBuilds(token, deploymentEnvironment,
startTime, endTime);
List<BuildKiteBuildInfo> buildKiteBuildInfo = buildKiteService
.fetchPipelineBuilds(token, deploymentEnvironment, startTime, endTime)
.stream()
.map(it -> {
if (Objects.isNull(it.getAuthor())) {
it.setAuthor(BuildKiteBuildInfo.Author.builder().username("Unknown").build());
}
return it;
})
.map(it -> {
if (Objects.isNull(it.getAuthor().getUsername())) {
it.getAuthor().setUsername(it.getAuthor().getName());
}
return it;
})
.toList();

if (!CollectionUtils.isEmpty(pipelineCrews)) {
buildKiteBuildInfo = buildKiteBuildInfo.stream()
.filter(info -> ((pipelineCrews.contains("Unknown") && info.getAuthor() == null))
|| (info.getAuthor() != null && pipelineCrews.contains(info.getAuthor().getName())))
.filter(info -> pipelineCrews.contains(info.getAuthor().getUsername()))
.toList();
}
return buildKiteBuildInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ class BuildKiteServiceTest {

BuildKiteService buildKiteService;

ThreadPoolTaskExecutor executor;

@BeforeEach
public void setUp() {
buildKiteService = new BuildKiteService(cachePageService, executor = getTaskExecutor(), buildKiteFeignClient);
buildKiteService = new BuildKiteService(cachePageService, getTaskExecutor(), buildKiteFeignClient);
}

public ThreadPoolTaskExecutor getTaskExecutor() {
Expand Down Expand Up @@ -132,7 +130,7 @@ public void shouldReturnResponseWhenFetchPipelineStepsSuccess() {
List<BuildKiteBuildInfo> buildKiteBuildInfoList = new ArrayList<>();
buildKiteBuildInfoList.add(BuildKiteBuildInfo.builder()
.jobs(List.of(testJob))
.author(BuildKiteBuildInfo.Author.builder().name("author").build())
.author(BuildKiteBuildInfo.Author.builder().username("author").build())
.creator(BuildKiteBuildInfo.Creator.builder().name("xx").build())
.build());
ResponseEntity<List<BuildKiteBuildInfo>> responseEntity = new ResponseEntity<>(buildKiteBuildInfoList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static List<PipelineCSVInfo> MOCK_PIPELINE_CSV_DATA() {
.finishedAt("2023-05-10T06:43:02.653Z")
.build()))
.branch("branch")
.author(BuildKiteBuildInfo.Author.builder().name("XXXX").build())
.author(BuildKiteBuildInfo.Author.builder().username("XXXX").build())
.build())
.commitInfo(CommitInfo.builder()
.commit(Commit.builder()
Expand Down Expand Up @@ -88,7 +88,7 @@ public static List<PipelineCSVInfo> MOCK_PIPELINE_CSV_DATA_WITHOUT_CREATOR() {
.finishedAt("2023-05-10T06:43:02.653Z")
.build()))
.branch("branch")
.author(BuildKiteBuildInfo.Author.builder().name("XXXX").build())
.author(BuildKiteBuildInfo.Author.builder().username("XXXX").build())
.build())
.commitInfo(CommitInfo.builder()
.commit(Commit.builder()
Expand Down Expand Up @@ -197,7 +197,7 @@ public static List<PipelineCSVInfo> MOCK_PIPELINE_CSV_DATA_WITH_MESSAGE_IS_REVER
.finishedAt("2023-05-10T06:43:02.653Z")
.build()))
.branch("branch")
.author(BuildKiteBuildInfo.Author.builder().name("XXXX").build())
.author(BuildKiteBuildInfo.Author.builder().username("XXXX").build())
.build())
.commitInfo(CommitInfo.builder()
.commit(Commit.builder()
Expand Down Expand Up @@ -309,7 +309,7 @@ public static List<PipelineCSVInfo> MOCK_PIPELINE_CSV_DATA_WITH_PIPELINE_STATUS_
.finishedAt("2023-05-10T06:43:02.653Z")
.build()))
.branch("branch")
.author(BuildKiteBuildInfo.Author.builder().name("XXXX").build())
.author(BuildKiteBuildInfo.Author.builder().username("XXXX").build())
.build())
.commitInfo(CommitInfo.builder()
.commit(Commit.builder()
Expand Down Expand Up @@ -364,7 +364,7 @@ public static List<PipelineCSVInfo> MOCK_PIPELINE_CSV_DATA_WITH_NULL_COMMIT_INFO
.finishedAt("2023-05-10T06:43:02.653Z")
.build()))
.branch("branch")
.author(BuildKiteBuildInfo.Author.builder().name("XXXX").build())
.author(BuildKiteBuildInfo.Author.builder().username("XXXX").build())
.build())
.leadTimeInfo(LeadTimeInfo.builder()
.firstCommitTimeInPr("2023-05-08T07:18:18Z")
Expand Down Expand Up @@ -457,7 +457,7 @@ public static List<PipelineCSVInfo> MOCK_TWO_ORGANIZATIONS_PIPELINE_CSV_DATA() {
.finishedAt("2023-05-10T06:43:02.653Z")
.build()))
.branch("branch")
.author(BuildKiteBuildInfo.Author.builder().name("XXXX").build())
.author(BuildKiteBuildInfo.Author.builder().username("XXXX").build())
.build())
.commitInfo(CommitInfo.builder()
.commit(Commit.builder()
Expand Down
Loading

0 comments on commit 35282c0

Please sign in to comment.