diff --git a/.gitignore b/.gitignore index 63bb3a7..848d8c3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,6 @@ release/nohup.out .factorypath .project .settings/ -release/env/* -!release/env/*.example +#release/env/* +#!release/env/*.example diff --git a/README.md b/README.md index 91c7084..ef9c22d 100644 --- a/README.md +++ b/README.md @@ -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 -``` \ No newline at end of file +``` + +## How to change jira application? +Open ```release/env/host.txt``` and change the host url. + +By default, we use ```https://arlive.atlassian.net``` diff --git a/release/2-getJiraReport.sh b/release/2-getJiraReport.sh index 4872073..6bcdfc0 100644 --- a/release/2-getJiraReport.sh +++ b/release/2-getJiraReport.sh @@ -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 diff --git a/release/env/host.txt b/release/env/host.txt new file mode 100644 index 0000000..c9d4a84 --- /dev/null +++ b/release/env/host.txt @@ -0,0 +1 @@ +jira-host: https://arlive.atlassian.net diff --git a/release/env/host.txt.example b/release/env/host.txt.example new file mode 100644 index 0000000..c9d4a84 --- /dev/null +++ b/release/env/host.txt.example @@ -0,0 +1 @@ +jira-host: https://arlive.atlassian.net diff --git a/src/main/java/com/tw/jiracalc/controller/JiraController.java b/src/main/java/com/tw/jiracalc/controller/JiraController.java index 355c0d3..9fe3848 100644 --- a/src/main/java/com/tw/jiracalc/controller/JiraController.java +++ b/src/main/java/com/tw/jiracalc/controller/JiraController.java @@ -33,7 +33,7 @@ String getCardsFile(@RequestHeader Map 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); } diff --git a/src/main/java/com/tw/jiracalc/service/CardHttpService.java b/src/main/java/com/tw/jiracalc/service/CardHttpService.java index 5e1c23e..ad00d83 100644 --- a/src/main/java/com/tw/jiracalc/service/CardHttpService.java +++ b/src/main/java/com/tw/jiracalc/service/CardHttpService.java @@ -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 response = restTemplate.exchange(url, HttpMethod.GET, entity, JiraCards.class); @@ -40,12 +40,12 @@ public JiraCards getCards(final String jql, final String jiraApiToken) { } @Async - public CompletableFuture> getCycleTime(final String jiraId, final String jiraToken) { + public CompletableFuture> 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 response = restTemplate.exchange(url, HttpMethod.GET, entity, JiraCardHistory.class); diff --git a/src/main/java/com/tw/jiracalc/service/JiraService.java b/src/main/java/com/tw/jiracalc/service/JiraService.java index abd677d..5b04370 100644 --- a/src/main/java/com/tw/jiracalc/service/JiraService.java +++ b/src/main/java/com/tw/jiracalc/service/JiraService.java @@ -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>> 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 -> { diff --git a/src/test/java/com/tw/jiracalc/controller/JiraControllerTest.java b/src/test/java/com/tw/jiracalc/controller/JiraControllerTest.java index 76836c7..33610b8 100644 --- a/src/test/java/com/tw/jiracalc/controller/JiraControllerTest.java +++ b/src/test/java/com/tw/jiracalc/controller/JiraControllerTest.java @@ -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 headers = new LinkedMultiValueMap<>(); diff --git a/src/test/java/com/tw/jiracalc/service/CardHttpServiceTest.java b/src/test/java/com/tw/jiracalc/service/CardHttpServiceTest.java index 2aa2cb1..db13082 100644 --- a/src/test/java/com/tw/jiracalc/service/CardHttpServiceTest.java +++ b/src/test/java/com/tw/jiracalc/service/CardHttpServiceTest.java @@ -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); }