# ignie-456: read contributors from jira
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/1471f200 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/1471f200 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/1471f200 Branch: refs/heads/ignite-456 Commit: 1471f200323ebeeefcd55537825577ea8203ee94 Parents: 460c89e Author: null <null> Authored: Mon May 25 14:33:37 2015 +0300 Committer: null <null> Committed: Mon May 25 14:33:37 2015 +0300 ---------------------------------------------------------------------- dev-tools/src/main/groovy/jiraslurp.groovy | 161 +++++++++++++---------- dev-tools/src/main/test.json | 162 ++++++++++++++++++++++++ 2 files changed, 259 insertions(+), 64 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1471f200/dev-tools/src/main/groovy/jiraslurp.groovy ---------------------------------------------------------------------- diff --git a/dev-tools/src/main/groovy/jiraslurp.groovy b/dev-tools/src/main/groovy/jiraslurp.groovy index 78c58a2..ec30aa8 100644 --- a/dev-tools/src/main/groovy/jiraslurp.groovy +++ b/dev-tools/src/main/groovy/jiraslurp.groovy @@ -15,6 +15,10 @@ * limitations under the License. */ +/* + * Start of util methods. + */ + def envVariable = { name, defaultVar -> def res = System.getenv(name as String) @@ -34,6 +38,79 @@ def envVariableAsList = { name, defaultList -> } /** + * Monitors given process and show errors if exist. + */ +def checkprocess = { process -> + process.waitFor() + + if (process.exitValue() != 0) { + println "Return code: " + process.exitValue() + println "Errout:\n" + process.err.text + + assert process.exitValue() == 0 || process.exitValue() == 128 + } +} + +/** + * Util method to send http request. + */ +def sendHttpRequest = { requestMethod, urlString, user, pwd, postData, contentType -> + URL url = new URL(urlString as String); + + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + + String encoded = new sun.misc.BASE64Encoder().encode("$user:$pwd".getBytes()); + + conn.setRequestProperty("Authorization", "Basic " + encoded); + + conn.setDoOutput(true); + conn.setRequestMethod(requestMethod); + + if (postData) { + conn.setRequestProperty("Content-Type", contentType); + conn.setRequestProperty("Content-Length", String.valueOf(postData.length())); + + OutputStream os = conn.getOutputStream(); + os.write(postData.getBytes()); + os.flush(); + os.close(); + } + + conn.connect(); + + // Read response. + BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); + + String response = ""; + String line; + + while ((line = br.readLine()) != null) + response += line + + br.close(); + + response +} + +/** + * Util method to send http POST request. + */ +def sendPostRequest = { urlString, user, pwd, postData, contentType -> + sendHttpRequest("POST", urlString, user, pwd, postData, contentType); +} + +/** + * Util method to send http GET request. + */ +def sendGetRequest = { urlString, user, pwd-> + sendHttpRequest("GET", urlString, user, pwd, null, null); +} + +/* + * End of util methods. + */ + +/** * Parsing a special filter from Apache Ignite JIRA and picking up latest by ID * attachments to process. */ @@ -49,17 +126,28 @@ final def JIRA_CMD = System.getProperty('JIRA_COMMAND', 'jira.sh') final def TC_PROJECT_NAME = envVariable("PROJECT_NAME", "Ignite") final def TC_BUILD_EXCLUDE_LIST = envVariableAsList("BUILD_ID_EXCLUDES", ["Ignite_RunAllTestBuilds"]) +final def JIRA_USER = System.getenv('JIRA_USER') +final def JIRA_PWD = System.getenv('JIRA_PWD') + def getContributors = { - def contributorsFile = new File("../contributors.txt") + def response = sendGetRequest( + "$JIRA_URL/jira/rest/api/2/project/12315922/role/10010" as String, + JIRA_USER, + JIRA_PWD) + + println "Response on contributors request = $response" - assert contributorsFile.exists(), "There was not found file ${contributorsFile.getAbsolutePath()}. " + - "It have to be line separated list of jira usernames" + def json = new groovy.json.JsonSlurper().parseText(response) - contributorsList = contributorsFile.text.split('\n') + def contributors = [] - println "Contributors list: $contributorsList" + json.actors.each { + contributors.add(it.name) + } + + println "Contributors list: $contributors" - contributorsList + contributors } final def CONTRIBUTORS = getContributors() @@ -100,7 +188,7 @@ def getLatestAttachment = { jira -> .find { def fName = [email protected]() - CONTRIBUTORS.contains(it.@author as String) && + CONTRIBUTORS.contains(it.@author as String) && (fName.endsWith(".patch") || fName.endsWith(".txt") || fName.endsWith(".diff")) } @@ -151,20 +239,6 @@ def findAttachments = { } /** - * Monitors given process and show errors if exist. - */ -def checkprocess = { process -> - process.waitFor() - - if (process.exitValue() != 0) { - println "Return code: " + process.exitValue() - println "Errout:\n" + process.err.text - - assert process.exitValue() == 0 || process.exitValue() == 128 - } -} - -/** * Applys patch from jira to given git state. */ def applyPatch = { jira, attachementURL -> @@ -245,50 +319,9 @@ def getTestBuilds = { -> } /** - * Util method to send post request. - */ -def sendPostRequest = { urlString, user, pwd, postData, contentType -> - URL url = new URL(urlString as String); - - HttpURLConnection conn = (HttpURLConnection)url.openConnection(); - - String encoded = new sun.misc.BASE64Encoder().encode("$user:$pwd".getBytes()); - - conn.setRequestProperty("Authorization", "Basic " + encoded); - - conn.setDoOutput(true); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", contentType); - conn.setRequestProperty("Content-Length", String.valueOf(postData.length())); - - OutputStream os = conn.getOutputStream(); - os.write(postData.getBytes()); - os.flush(); - os.close(); - - conn.connect(); - - // Read response. - BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); - - String response = ""; - String line; - - while ((line = br.readLine()) != null) - response += line - - br.close(); - - response -} - -/** * Adds comment to jira ticket. */ def addJiraComment = { jiraNum, comment -> - def user = System.getenv('JIRA_USER') - def pwd = System.getenv('JIRA_PWD') - try { println "Comment: $comment" @@ -296,8 +329,8 @@ def addJiraComment = { jiraNum, comment -> def response = sendPostRequest( "$JIRA_URL/jira/rest/api/2/issue/$jiraNum/comment" as String, - user, - pwd, + JIRA_USER, + JIRA_PWD, jsonComment, "application/json") http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1471f200/dev-tools/src/main/test.json ---------------------------------------------------------------------- diff --git a/dev-tools/src/main/test.json b/dev-tools/src/main/test.json new file mode 100644 index 0000000..15ac685 --- /dev/null +++ b/dev-tools/src/main/test.json @@ -0,0 +1,162 @@ +{ + "self": "https://issues.apache.org/jira/rest/api/2/project/12315922/role/10010", + "name": "Contributors", + "id": 10010, + "description": "Non-committers who help out with development", + "actors": [ + { + "id": 40295, + "displayName": "Andrey Gura", + "type": "atlassian-user-role-actor", + "name": "agura", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 42992, + "displayName": "Andrey Kornev", + "type": "atlassian-user-role-actor", + "name": "avk47", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 39706, + "displayName": "Anton Vinogradov", + "type": "atlassian-user-role-actor", + "name": "avinogradov", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 39771, + "displayName": "Artem Shutak", + "type": "atlassian-user-role-actor", + "name": "ashutak", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 42255, + "displayName": "Ashwin Sharma", + "type": "atlassian-user-role-actor", + "name": "ashwinks11", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 42238, + "displayName": "Atri Sharma", + "type": "atlassian-user-role-actor", + "name": "atris", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 42206, + "displayName": "Denis Magda", + "type": "atlassian-user-role-actor", + "name": "dmagda", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 43065, + "displayName": "Evans Ye", + "type": "atlassian-user-role-actor", + "name": "evans_ye", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 42766, + "displayName": "Gianfranco Murador", + "type": "atlassian-user-role-actor", + "name": "glutters", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 42700, + "displayName": "Iker Huerga", + "type": "atlassian-user-role-actor", + "name": "ihuerga", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 39834, + "displayName": "Ilya Suntsov", + "type": "atlassian-user-role-actor", + "name": "ustas", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&ownerId=ustas&avatarId=22922" + }, + { + "id": 39705, + "displayName": "Irina Vasilinets", + "type": "atlassian-user-role-actor", + "name": "vasilinets", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 40058, + "displayName": "Ivan Veselovsky", + "type": "atlassian-user-role-actor", + "name": "iveselovskiy", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 40516, + "displayName": "Joshua Goldie", + "type": "atlassian-user-role-actor", + "name": "jdgoldie", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&ownerId=jdgoldie&avatarId=23036" + }, + { + "id": 40344, + "displayName": "Mikhail Antonov", + "type": "atlassian-user-role-actor", + "name": "mantonov", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&ownerId=mantonov&avatarId=18652" + }, + { + "id": 39247, + "displayName": "Nikolay Tikhonov", + "type": "atlassian-user-role-actor", + "name": "ntikhonov", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 39835, + "displayName": "Pavel Konstantinov", + "type": "atlassian-user-role-actor", + "name": "pkonstantinov", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&ownerId=pkonstantinov&avatarId=22948" + }, + { + "id": 42226, + "displayName": "Sergey Eliseev", + "type": "atlassian-user-role-actor", + "name": "SergeyEliseev", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 39833, + "displayName": "Sergey Kozlov", + "type": "atlassian-user-role-actor", + "name": "skozlov", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 40146, + "displayName": "Vasilisa Sidorova", + "type": "atlassian-user-role-actor", + "name": "vsidorova", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10449" + }, + { + "id": 39798, + "displayName": "Vasiliy Sisko", + "type": "atlassian-user-role-actor", + "name": "vsisko", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + }, + { + "id": 40343, + "displayName": "Vishal Garg", + "type": "atlassian-user-role-actor", + "name": "Vishal.garg.ignite", + "avatarUrl": "/jira/secure/useravatar?size=xsmall&avatarId=10452" + } + ] +}
