-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Prudhvi Godithi <[email protected]>
- Loading branch information
1 parent
e359325
commit 14c2327
Showing
8 changed files
with
225 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/org/opensearchmetrics/metrics/release/ReleaseIssueChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.opensearchmetrics.metrics.release; | ||
|
||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.index.query.BoolQueryBuilder; | ||
import org.opensearch.index.query.QueryBuilders; | ||
import org.opensearch.search.SearchHit; | ||
import org.opensearch.search.aggregations.AggregationBuilders; | ||
import org.opensearch.search.aggregations.bucket.terms.Terms; | ||
import org.opensearch.search.builder.SearchSourceBuilder; | ||
import org.opensearchmetrics.util.OpenSearchUtil; | ||
|
||
import javax.inject.Inject; | ||
import java.util.Arrays; | ||
|
||
public class ReleaseIssueChecker { | ||
|
||
@Inject | ||
public ReleaseIssueChecker() {} | ||
|
||
public String[] releaseOwners(String releaseVersion, String repo, OpenSearchUtil openSearchUtil) { | ||
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); | ||
boolQueryBuilder.must(QueryBuilders.matchQuery("repository.keyword", repo)); | ||
boolQueryBuilder.must(QueryBuilders.matchQuery("title.keyword", "[RELEASE] Release version " + releaseVersion)); | ||
boolQueryBuilder.must(QueryBuilders.matchQuery("issue_pull_request", false)); | ||
SearchRequest searchRequest = new SearchRequest("github_issues"); | ||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | ||
searchSourceBuilder.query(boolQueryBuilder); | ||
searchSourceBuilder.size(9000); | ||
searchSourceBuilder.aggregation( | ||
AggregationBuilders.terms("issue_assignees") | ||
.field("issue_assignees.keyword") | ||
.size(50) | ||
); | ||
searchRequest.source(searchSourceBuilder); | ||
SearchResponse searchResponse = openSearchUtil.search(searchRequest); | ||
Terms termsAgg = searchResponse.getAggregations().get("issue_assignees"); | ||
return termsAgg.getBuckets().stream() | ||
.map(Terms.Bucket::getKeyAsString) | ||
.toArray(String[]::new); | ||
} | ||
|
||
public String releaseIssue(String releaseVersion, String repo, OpenSearchUtil openSearchUtil) { | ||
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); | ||
boolQueryBuilder.must(QueryBuilders.matchQuery("repository.keyword", repo)); | ||
boolQueryBuilder.must(QueryBuilders.matchQuery("title.keyword", "[RELEASE] Release version " + releaseVersion)); | ||
boolQueryBuilder.must(QueryBuilders.matchQuery("issue_pull_request", false)); | ||
SearchRequest searchRequest = new SearchRequest("github_issues"); | ||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | ||
searchSourceBuilder.query(boolQueryBuilder); | ||
searchSourceBuilder.size(9000); | ||
searchRequest.source(searchSourceBuilder); | ||
SearchResponse searchResponse = openSearchUtil.search(searchRequest); | ||
SearchHit[] hits = searchResponse.getHits().getHits(); | ||
return Arrays.stream(hits) | ||
.findFirst() | ||
.map(hit -> (String) hit.getSourceAsMap().get("html_url")) | ||
.orElse(null); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/test/java/org/opensearchmetrics/metrics/release/ReleaseIssueCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.opensearchmetrics.metrics.release; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.search.SearchHit; | ||
import org.opensearch.search.SearchHits; | ||
import org.opensearch.search.aggregations.Aggregations; | ||
import org.opensearch.search.aggregations.bucket.terms.Terms; | ||
import org.opensearchmetrics.util.OpenSearchUtil; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ReleaseIssueCheckerTest { | ||
|
||
@Mock | ||
private OpenSearchUtil openSearchUtil; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
void testReleaseOwners() { | ||
Terms.Bucket bucket1 = mock(Terms.Bucket.class); | ||
when(bucket1.getKeyAsString()).thenReturn("sample_user_1"); | ||
Terms.Bucket bucket2 = mock(Terms.Bucket.class); | ||
when(bucket2.getKeyAsString()).thenReturn("sample_user_2"); | ||
Terms.Bucket bucket3 = mock(Terms.Bucket.class); | ||
when(bucket3.getKeyAsString()).thenReturn("sample_user_3"); | ||
Terms.Bucket bucket4 = mock(Terms.Bucket.class); | ||
when(bucket4.getKeyAsString()).thenReturn("sample_user_4"); | ||
List<Terms.Bucket> buckets = Arrays.asList(bucket1, bucket2, bucket3, bucket4); | ||
Terms termsAgg = mock(Terms.class); | ||
when(termsAgg.getBuckets()).thenAnswer(invocation -> buckets); | ||
Aggregations aggregations = mock(Aggregations.class); | ||
when(aggregations.get("issue_assignees")).thenReturn(termsAgg); | ||
SearchResponse searchResponse = mock(SearchResponse.class); | ||
when(searchResponse.status()).thenReturn(RestStatus.OK); | ||
when(searchResponse.getAggregations()).thenReturn(aggregations); | ||
OpenSearchUtil openSearchUtil = mock(OpenSearchUtil.class); | ||
when(openSearchUtil.search(any(SearchRequest.class))).thenReturn(searchResponse); | ||
ReleaseIssueChecker releaseIssueChecker = new ReleaseIssueChecker(); | ||
String[] result = releaseIssueChecker.releaseOwners("2.16.0", "opensearch-build", openSearchUtil); | ||
String[] expected = {"sample_user_1", "sample_user_2", "sample_user_3", "sample_user_4"}; | ||
assertArrayEquals(expected, result); | ||
} | ||
|
||
@Test | ||
void testReleaseIssue() { | ||
SearchHit hit1 = mock(SearchHit.class); | ||
when(hit1.getSourceAsMap()).thenReturn(Map.of("html_url", "https://github.com/opensearch-project/opensearch-build/issues/4115")); | ||
SearchHit hit2 = mock(SearchHit.class); | ||
when(hit2.getSourceAsMap()).thenReturn(Map.of("html_url", "https://github.com/opensearch-project/opensearch-build/issues/4454")); | ||
SearchHits searchHits = mock(SearchHits.class); | ||
when(searchHits.getHits()).thenReturn(new SearchHit[]{hit1, hit2}); | ||
SearchResponse searchResponse = mock(SearchResponse.class); | ||
when(searchResponse.getHits()).thenReturn(searchHits); | ||
when(searchResponse.status()).thenReturn(RestStatus.OK); | ||
OpenSearchUtil openSearchUtil = mock(OpenSearchUtil.class); | ||
when(openSearchUtil.search(any(SearchRequest.class))).thenReturn(searchResponse); | ||
ReleaseIssueChecker releaseIssueChecker = new ReleaseIssueChecker(); | ||
String result = releaseIssueChecker.releaseIssue("2.16.0", "opensearch-build", openSearchUtil); | ||
assertEquals("https://github.com/opensearch-project/opensearch-build/issues/4115", result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.