Skip to content

Commit 72160de

Browse files
authored
Merge pull request #319 from fffinkel/master
Add issue status change example to README
2 parents 6be9c38 + e8e35b6 commit 72160de

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,49 @@ func main() {
173173
}
174174
```
175175

176+
### Change an issue status
177+
178+
This is how one can change an issue status. In this example, we change the issue from "To Do" to "In Progress."
179+
180+
```go
181+
package main
182+
183+
import (
184+
"fmt"
185+
"github.com/andygrunwald/go-jira"
186+
)
187+
188+
func main() {
189+
base := "https://my.jira.com"
190+
tp := jira.BasicAuthTransport{
191+
Username: "username",
192+
Password: "token",
193+
}
194+
195+
jiraClient, err := jira.NewClient(tp.Client(), base)
196+
if err != nil {
197+
panic(err)
198+
}
199+
200+
issue, _, _ := jiraClient.Issue.Get("FART-1", nil)
201+
currentStatus := issue.Fields.Status.Name
202+
fmt.Printf("Current status: %s\n", currentStatus)
203+
204+
var transitionID string
205+
possibleTransitions, _, _ := jiraClient.Issue.GetTransitions("FART-1")
206+
for _, v := range possibleTransitions {
207+
if v.Name == "In Progress" {
208+
transitionID = v.ID
209+
break
210+
}
211+
}
212+
213+
jiraClient.Issue.DoTransition("FART-1", transitionID)
214+
issue, _, _ = jiraClient.Issue.Get(testIssueID, nil)
215+
fmt.Printf("Status after transition: %+v\n", issue.Fields.Status.Name)
216+
}
217+
```
218+
176219
### Call a not implemented API endpoint
177220

178221
Not all API endpoints of the Jira API are implemented into *go-jira*.

0 commit comments

Comments
 (0)