Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

Getting null project key in a Jira Cloud App sprint_started webhook

I'm developing a Jira Cloud Add on that will receive sprint related events:

  "modules": {
    "webhooks": [
      {
        "event": "sprint_started",
        "url": "/sprints/started?project={project.key}&id={project.id}"
      },
      {
        "event": "sprint_closed",
        "url": "/sprints/closed?project={project.key}&id={project.id}"
      }

As described in the documentation I've used the placeholders {project.key} and {project.id} to get the information about the project in which the event was triggered.

This is the controller that is invoked:

    @PostMapping(value = ["/started", "/closed"])
    fun sprintEvent(@AuthenticationPrincipal hostUser: AtlassianHostUser, @RequestParam project: String, @RequestParam id: String, @RequestBody body: Map<String, Any>): Mono<Void> {

However both project and id are null

The same thing for issue events works smoothly, receiving the project key:

  "modules": {
    "webhooks": [
      {
        "event": "jira:issue_created",
        "url": "/issues/created?project={project.key}&issue={issue.key}"
      },
    @PostMapping(value = ["/created", "/updated"])
    fun issueEvent(@AuthenticationPrincipal hostUser: AtlassianHostUser, @RequestParam project: String, @RequestParam issue: String, @RequestBody body: Map<String, Any>): Mono<Void> {

What's the problem with the sprint events?

question from:https://stackoverflow.com/questions/65647524/getting-null-project-key-in-a-jira-cloud-app-sprint-started-webhook

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There seems to be a limitation in which those properties aren't available in the sprint event "context".

My workaround was:

  1. Get the board id:
val boardId = (body["sprint"] as Map<String, Any?>)["originBoardId"] as Int
  1. Get the whole board information with the atlassian rest client:
val board = atlassianHostRestClients.authenticatedAsAddon().getForObject("/rest/agile/1.0/board/{boardId}", Map::class.java, boardId) as Map<String, *>`
  1. Extract the project key from there:
val projectKey = (board["location"] as Map<String, *>)["projectKey"] as String

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...