Skip to content

Commit

Permalink
Add a comment to the latest
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi committed Jul 24, 2023
1 parent 8776b89 commit 861c538
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jacocoTestReport {
}
}

String version = '5.2.0'
String version = '5.3.0'

task updateVersion {
doLast {
Expand Down
5 changes: 4 additions & 1 deletion tests/jenkins/TestCreateBuildFailureGithubIssue.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class TestCreateBuildFailureGithubIssue extends BuildPipelineTest {
@Test
public void testExistingGithubIssue() {
super.testPipeline('tests/jenkins/jobs/CreateBuildFailureGithubIssue_Jenkinsfile', 'tests/jenkins/jobs/CreateBuildFailureGithubExistingIssueCheck_Jenkinsfile')
assertThat(getCommands('println', ''), hasItem('Issue already exists in the repository, skipping.'))
assertThat(getCommands('println', ''), hasItem('Issue already exists, adding a comment.'))
assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/OpenSearch.git -S \"[AUTOCUT] Distribution Build Failed for OpenSearch-2.0.0 in:title\" --label autocut,v2.0.0, returnStdout=true}"))
assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/OpenSearch.git -S \"[AUTOCUT] Distribution Build Failed for OpenSearch-2.0.0 in:title\" --label autocut,v2.0.0 --json number --jq '.[0].number', returnStdout=true}"))
assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue comment \nbbb\nccc\n --repo https://github.com/opensearch-project/OpenSearch.git --body \"***Received Error***: **Error building OpenSearch, retry with: ./build.sh manifests/2.2.0/opensearch-2.2.0.yml --component OpenSearch --snapshot**.\n The distribution build for OpenSearch has failed for version: 2.0.0.\n Please see build log at www.example.com/jobs/test/123/consoleFull\", returnStdout=true}"))
}

def getCommands(method, text) {
Expand Down
8 changes: 5 additions & 3 deletions tests/jenkins/TestCreateGithubIssue.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ class TestCreateGithubIssue extends BuildPipelineTest {
this.registerLibTester(new CreateGithubIssueLibTester(
'https://github.com/opensearch-project/opensearch-build',
'Test GH issue title',
'Test GH issue body'
'Test GH issue body',
))
super.testPipeline('tests/jenkins/jobs/CreateGithubIssueExisting_JenkinsFile')
assertThat(getCommands('println', ''), hasItem('Issue already exists in the repository, skipping.'))
assertThat(getCommands('sh', 'script'), hasItem('{script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S "Test GH issue title in:title" --label autocut, returnStdout=true}'))
assertThat(getCommands('println', ''), hasItem('Issue already exists, adding a comment.'))
assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S \"Test GH issue title in:title\" --label autocut, returnStdout=true}"))
assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S \"Test GH issue title in:title\" --label autocut --json number --jq '.[0].number', returnStdout=true}"))
assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue comment \nbbb\nccc\n --repo https://github.com/opensearch-project/opensearch-build --body \"Test GH issue body\", returnStdout=true}"))
}

def getCommands(method, text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
createGithubIssue.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER})
createGithubIssue.withCredentials([[GITHUB_USER, GITHUB_TOKEN]], groovy.lang.Closure)
createGithubIssue.sh({script=gh issue list --repo https://github.com/opensearch-project/OpenSearch.git -S "[AUTOCUT] Distribution Build Failed for OpenSearch-2.0.0 in:title" --label autocut,v2.0.0, returnStdout=true})
createGithubIssue.println(Issue already exists in the repository, skipping.)
createGithubIssue.println(Issue already exists, adding a comment.)
createGithubIssue.sh({script=gh issue list --repo https://github.com/opensearch-project/OpenSearch.git -S "[AUTOCUT] Distribution Build Failed for OpenSearch-2.0.0 in:title" --label autocut,v2.0.0 --json number --jq '.[0].number', returnStdout=true})
createGithubIssue.sh({script=gh issue comment
bbb
ccc
--repo https://github.com/opensearch-project/OpenSearch.git --body "***Received Error***: **Error building OpenSearch, retry with: ./build.sh manifests/2.2.0/opensearch-2.2.0.yml --component OpenSearch --snapshot**.
The distribution build for OpenSearch has failed for version: 2.0.0.
Please see build log at www.example.com/jobs/test/123/consoleFull", returnStdout=true})
createBuildFailureGithubIssue.sleep({time=3, unit=SECONDS})
7 changes: 6 additions & 1 deletion tests/jenkins/jobs/CreateGithubIssueExisting_JenkinsFile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
createGithubIssue.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER})
createGithubIssue.withCredentials([[GITHUB_USER, GITHUB_TOKEN]], groovy.lang.Closure)
createGithubIssue.sh({script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S "Test GH issue title in:title" --label autocut, returnStdout=true})
createGithubIssue.println(Issue already exists in the repository, skipping.)
createGithubIssue.println(Issue already exists, adding a comment.)
createGithubIssue.sh({script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S "Test GH issue title in:title" --label autocut --json number --jq '.[0].number', returnStdout=true})
createGithubIssue.sh({script=gh issue comment
bbb
ccc
--repo https://github.com/opensearch-project/opensearch-build --body "Test GH issue body", returnStdout=true})
10 changes: 9 additions & 1 deletion vars/createGithubIssue.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ void call(Map args = [:]) {
)

if (issues) {
println('Issue already exists in the repository, skipping.')
println('Issue already exists, adding a comment.')
def issuesNumber = sh(
script: "gh issue list --repo ${args.repoUrl} -S \"${args.issueTitle} in:title\" --label ${label} --json number --jq '.[0].number'",
returnStdout: true
)
sh(
script: "gh issue comment ${issuesNumber} --repo ${args.repoUrl} --body \"${args.issueBody}\"",
returnStdout: true
)
}
else {
sh(
Expand Down

0 comments on commit 861c538

Please sign in to comment.