Posted By

4fthawaiian on 03/08/16


Tagged


Versions (?)

change lead of jira project using scriptrunner custom endpoint


 / Published in: Groovy
 

after this is added into the custom REST endpoints for scriptrunner, you can run it this way: /rest/scriptrunner/latest/custom/updateLead?userName=USERNAME&projectKey=PROJECTKEY

  1. import com.atlassian.jira.ComponentManager
  2. import com.atlassian.jira.project.ProjectManager
  3.  
  4. import com.atlassian.jira.project.Project
  5.  
  6. import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
  7. import groovy.json.JsonBuilder
  8. import groovy.transform.BaseScript
  9.  
  10. import javax.ws.rs.core.MultivaluedMap
  11. import javax.ws.rs.core.Response
  12.  
  13. @BaseScript CustomEndpointDelegate delegate
  14.  
  15. updateLead(
  16. httpMethod: "GET", groups: ["jira-administrators"]
  17. ) { MultivaluedMap queryParams, String body ->
  18. ComponentManager componentManager = ComponentManager.getInstance()
  19. ProjectManager projectManager = componentManager.getProjectManager()
  20.  
  21. String userToElevate
  22. String projectToFind
  23. Project theProject
  24.  
  25. try {
  26. userToElevate = queryParams.get("userName")[0].toString()
  27. }
  28. catch(java.lang.NullPointerException e) {
  29. return Response.serverError().entity([error: "please supply userName"]).build();
  30. }
  31. try {
  32. projectToFind = queryParams.get("projectKey")[0].toString()
  33. }
  34. catch(java.lang.NullPointerException e) {
  35. return Response.serverError().entity([error: "please supply projectKey"]).build();
  36. }
  37. try {
  38. theProject = projectManager.getProjectObjByKey(projectToFind)
  39. }
  40. catch(java.lang.NullPointerException e) {
  41. return Response.serverError().entity([error: "couldn't find project \"$projectToFind\""]).build();
  42. }
  43.  
  44. String projName = theProject.getName()
  45. String projDesc = theProject.getDescription()
  46. Long projAssignee = theProject.getAssigneeType()
  47. String projUrl = theProject.getUrl()
  48.  
  49. Project updatedProject = projectManager.updateProject(theProject,
  50. projName,
  51. projDesc,
  52. userToElevate, projUrl,
  53. projAssignee
  54. )
  55.  
  56. return Response.ok(new JsonBuilder([userName: "$userToElevate"]).toString()).build()
  57. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: 76422937 on March 8, 2016

verygood

You need to login to post a comment.