Skip to content

Commit

Permalink
Jira host relies on external config
Browse files Browse the repository at this point in the history
  • Loading branch information
PhonyLou committed May 11, 2020
1 parent e5db47e commit b644a3d
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ release/nohup.out
.factorypath
.project
.settings/
release/env/*
!release/env/*.example
#release/env/*
#!release/env/*.example

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ jql: project = Ao-li-gei AND (assignee in (Aotian.Long, Liangchen.ye, TieChui.Zh
#### Stages:
```
card-stage: Backlog, Analysis, Selected for Development, In-Progress, Showcase, Done
```
```
## How to change jira application?
Open ```release/env/host.txt``` and change the host url.
By default, we use ```https://arlive.atlassian.net```
2 changes: 1 addition & 1 deletion release/2-getJiraReport.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
now="$(date +"%Y-%m-%d %H:%M:%S")"
#echo $now
curl -X GET http://localhost:8081/jira/getCardsFile -H "$(cat ./env/jql.txt)" -H "$(cat ./env/token.txt)" -H "$(cat ./env/stages.txt)" > $now.csv
curl -X GET http://localhost:8081/jira/getCardsFile -H "$(cat ./env/jql.txt)" -H "$(cat ./env/token.txt)" -H "$(cat ./env/stages.txt)" -H "$(cat ./env/host.txt)" > $now.csv
1 change: 1 addition & 0 deletions release/env/host.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jira-host: https://arlive.atlassian.net
1 change: 1 addition & 0 deletions release/env/host.txt.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jira-host: https://arlive.atlassian.net
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ String getCardsFile(@RequestHeader Map<String, String> header) {
.stream().map(String::trim).collect(Collectors.toList());

return fileService.generateCycleTimeFile(
jiraService.getCards(header.get("jql"), header.get("jira-token")),
jiraService.getCards(header.get("jql"), header.get("jira-token"), header.get("jira-host")),
displayStages);
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/tw/jiracalc/service/CardHttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public CardHttpService(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}

public JiraCards getCards(final String jql, final String jiraApiToken) {
public JiraCards getCards(final String jql, final String jiraApiToken, final String jiraHost) {
logger.info("JiraService.getCards starts");
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
headers.set("Authorization", jiraApiToken);

String url = "https://arlive.atlassian.net/rest/api/2/search?jql=" + jql;
String url = jiraHost + "/rest/api/2/search?jql=" + jql;

HttpEntity<?> entity = new HttpEntity<>(headers);
HttpEntity<JiraCards> response = restTemplate.exchange(url, HttpMethod.GET, entity, JiraCards.class);
Expand All @@ -40,12 +40,12 @@ public JiraCards getCards(final String jql, final String jiraApiToken) {
}

@Async
public CompletableFuture<Map<String, Double>> getCycleTime(final String jiraId, final String jiraToken) {
public CompletableFuture<Map<String, Double>> getCycleTime(final String jiraId, final String jiraToken, final String jiraHost) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
headers.set("Authorization", jiraToken);

String url = "https://arlive.atlassian.net/rest/internal/2/issue/"+jiraId+"/activityfeed";
String url = jiraHost + "/rest/internal/2/issue/"+jiraId+"/activityfeed";
HttpEntity<?> entity = new HttpEntity<>(headers);
HttpEntity<JiraCardHistory> response = restTemplate.exchange(url, HttpMethod.GET, entity, JiraCardHistory.class);

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/tw/jiracalc/service/JiraService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public JiraService(CardHttpService cardHttpService) {
this.cardHttpService = cardHttpService;
}

public JiraCards getCards(final String jql, final String jiraApiToken) {
public JiraCards getCards(final String jql, final String jiraApiToken, final String jiraHost) {
logger.info("enrichCardDetail starts");
final Map<String, CompletableFuture<Map<String, Double>>> cycleTimeMap = new HashMap<>();
final JiraCards jiraCards = cardHttpService.getCards(jql, jiraApiToken);
jiraCards.issues.forEach(card -> cycleTimeMap.put(card.key, cardHttpService.getCycleTime(card.key, jiraApiToken)));
final JiraCards jiraCards = cardHttpService.getCards(jql, jiraApiToken, jiraHost);
jiraCards.issues.forEach(card -> cycleTimeMap.put(card.key, cardHttpService.getCycleTime(card.key, jiraApiToken, jiraHost)));
logger.info("enrichCardDetail ends");

jiraCards.issues.forEach(card -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class JiraControllerTest {
void return_string_when_normal() throws Exception {
final String expect = "Mock Result";

when(jiraService.getCards(any(), any())).thenReturn(new JiraCards());
when(jiraService.getCards(any(), any(), any())).thenReturn(new JiraCards());
when(fileService.generateCycleTimeFile(any(), any())).thenReturn("Mock Result");

MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void CardHttpService_getCards_health_check() {
.when(restTemplate)
.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), eq(JiraCards.class));

JiraCards jiraCards = cardHttpService.getCards("jql", "jiraApiToken");
JiraCards jiraCards = cardHttpService.getCards("jql", "jiraApiToken", "jiraHost");
Assertions.assertEquals(expect, jiraCards);
}

Expand Down

0 comments on commit b644a3d

Please sign in to comment.