๐Ÿ’ผ
Roles
This resource represents the roles that users can play in projects. Use this resource to get, create, update, and delete project roles.

Get project roles for project

Returns a list of project roles for the project returning the name and self URL for each role.
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)
โ€‹
roles, response, err := atlassian.Project.Role.Gets(context.Background(), "KP")
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for key, value := range *roles {
log.Println(key, value)
}
}

Get project role for project

Returns a project role's details and actors associated with the project. The list of actors is sorted by display name.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira"
"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 := jira.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
role, response, err := atlassian.Project.Role.Get(context.Background(), "KP", 10005)
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
log.Println(role.ID)
log.Println(role.Name)
log.Println(role.Description)
log.Println(role.Self)
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type ProjectRoleScheme struct {
Self string `json:"self,omitempty"`
Name string `json:"name,omitempty"`
ID int `json:"id,omitempty"`
Description string `json:"description,omitempty"`
Actors []*RoleActorScheme `json:"actors,omitempty"`
Scope *TeamManagedProjectScopeScheme `json:"scope,omitempty"`
TranslatedName string `json:"translatedName,omitempty"`
CurrentUserRole bool `json:"currentUserRole,omitempty"`
Admin bool `json:"admin,omitempty"`
RoleConfigurable bool `json:"roleConfigurable,omitempty"`
Default bool `json:"default,omitempty"`
}
โ€‹
type RoleActorScheme struct {
ID int `json:"id,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
AvatarURL string `json:"avatarUrl,omitempty"`
ActorUser struct {
AccountID string `json:"accountId,omitempty"`
} `json:"actorUser,omitempty"`
ActorGroup *GroupScheme `json:"actorGroup,omitempty"`
}

Get project role details

Returns all project roles and the details for each role. Note that the list of project roles is common to all projects.
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)
โ€‹
rolesDetails, response, err := atlassian.Project.Role.Details(context.Background(), "KP")
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, role := range rolesDetails {
log.Println(role.Name)
log.Println(role.ID)
log.Println(role.Admin)
log.Println(role.TranslatedName)
}
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type ProjectRoleDetailScheme struct {
Self string `json:"self,omitempty"`
Name string `json:"name,omitempty"`
ID int `json:"id,omitempty"`
Description string `json:"description,omitempty"`
Admin bool `json:"admin,omitempty"`
Scope *TeamManagedProjectScopeScheme `json:"scope,omitempty"`
RoleConfigurable bool `json:"roleConfigurable,omitempty"`
TranslatedName string `json:"translatedName,omitempty"`
Default bool `json:"default,omitempty"`
}

Get all project roles

Gets a list of all project roles, complete with project role details and default actors.
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)
โ€‹
roles, response, err := atlassian.Project.Role.Global(context.Background())
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, role := range roles {
log.Println(role)
}
}

Create project role

Creates a new project role with no default actors.
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)
โ€‹
var payload = &models.ProjectRolePayloadScheme{
Name: "Developers",
Description: "A project role that represents developers in a project",
}
โ€‹
newRole, response, err := atlassian.Project.Role.Create(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(newRole)
}