๐Ÿงฑ
Versions
This resource represents project versions. Use it to get, get lists of, create, update, move, merge, and delete project versions. This resource also provides counts of issues by version.

Get project versions

Returns all versions in a project. The response is not paginated.
package main
โ€‹
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
versions, response, err := atlassian.Project.Version.Gets(context.Background(), "KP")
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, version := range versions {
fmt.Println(version)
}
}

Create version

Creates a project version.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
payload := &models.VersionPayloadScheme{
Archived: false,
ReleaseDate: "2021-03-06",
Name: "Version Sandbox",
Description: "Version Sandbox description",
ProjectID: 10000,
Released: false,
StartDate: "2021-03-02",
}
โ€‹
newVersion, response, err := atlassian.Project.Version.Create(context.Background(), payload)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("The new version has been created with the ID %v", newVersion.ID)
}

Get version

Returns a project version.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
version, response, err := atlassian.Project.Version.Get(context.Background(), "10002", []string{"issuesstatus", "operations"})
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(version)
}

Update version

Updates a project version.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
payload := &models.VersionPayloadScheme{
Archived: false,
Name: "Version Sandbox - UPDATED",
Description: "Version Sandbox description - UPDATED",
ProjectID: 10000,
Released: true,
}
โ€‹
versionUpdated, response, err := atlassian.Project.Version.Update(context.Background(), "10002", payload)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(versionUpdated)
}

Merge versions

Merges two project versions. The merge is completed by deleting the version specified in id and replacing any occurrences of its ID in fixVersion with the version ID specified in moveIssuesTo.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
response, err := atlassian.Project.Version.Merge(context.Background(), "10001", "10000")
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}

Get version's related issues count

Returns the following counts for a version:
  • Number of issues where the fixVersion is set to the version.
  • Number of issues where the affectedVersion is set to the version.
  • Number of issues where a version custom field is set to the version.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
count, response, err := atlassian.Project.Version.RelatedIssueCounts(context.Background(), "10002")
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println(response.Endpoint)
log.Println(count)
โ€‹
}

Get version's unresolved issues count

Returns counts of the issues and unresolved issues for the project version.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
count, response, err := atlassian.Project.Version.UnresolvedIssueCount(context.Background(), "10000")
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(count)
}
Last modified 8mo ago