๐Ÿ”ฎ
Components
This resource represents project components. Uses to get, create, update, and delete project components. Also get components for project and get a count of issues by component.

Create component

Creates a component. Use components to provide containers for issues within a project.
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.ComponentPayloadScheme{
IsAssigneeTypeValid: false,
Name: "Component 2",
Description: "This is a Jira component",
Project: "KP",
AssigneeType: "PROJECT_LEAD",
LeadAccountID: "5b86be50b8e3cb5895860d6d",
}
โ€‹
newComponent, response, err := atlassian.Project.Component.Create(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("The new component has been created with the ID %v", newComponent.ID)
}

Get component

Returns a component.
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)
โ€‹
component, response, err := atlassian.Project.Component.Get(context.Background(), "10006")
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println(component)
log.Println(response.Endpoint)
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type ComponentScheme struct {
Self string `json:"self,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Lead *UserScheme `json:"lead,omitempty"`
LeadUserName string `json:"leadUserName,omitempty"`
AssigneeType string `json:"assigneeType,omitempty"`
Assignee *UserScheme `json:"assignee,omitempty"`
RealAssigneeType string `json:"realAssigneeType,omitempty"`
RealAssignee *UserScheme `json:"realAssignee,omitempty"`
IsAssigneeTypeValid bool `json:"isAssigneeTypeValid,omitempty"`
Project string `json:"project,omitempty"`
ProjectID int `json:"projectId,omitempty"`
}

Update component

Updates a component. Any fields included in the request are overwritten. If leadAccountId is an empty string ("") the component lead is removed.
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.ComponentPayloadScheme{
IsAssigneeTypeValid: false,
Name: "Component 1 - UPDATED",
Description: "This is a Jira component - UPDATED",
}
โ€‹
componentUpdated, response, err := atlassian.Project.Component.Update(context.Background(), "10006", payload)
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println(response.Endpoint)
log.Println(componentUpdated)
}

Delete component

Deletes a component.
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.Component.Delete(context.Background(), "10006")
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("HTTP Endpoint Used", response.Endpoint)
}

Get component issues count

Returns the counts of issues assigned to the component.
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.Component.Count(context.Background(), "10005")
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println(count)
log.Println(response.Endpoint)
}

Get project components paginated

Returns a paginated list of all components in a project
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)
โ€‹
var projectKey = "KP"
components, response, err := atlassian.Project.Component.Gets(context.Background(), projectKey)
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println(response.Endpoint)
for _, component := range components {
log.Println(component)
}
}