Skip to content

Commit

Permalink
move issues from next-terraform-provider-release to release version
Browse files Browse the repository at this point in the history
  • Loading branch information
lantoli committed Apr 15, 2024
1 parent dec9072 commit 12d6bf8
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions tools/jira-release-version/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ import (
)

const (
envJira = "JIRA_API_TOKEN"
envVersion = "VERSION_NUMBER"
projectName = "CLOUDP"
jiraURL = "https://jira.mongodb.org"
versionPrefix = "terraform-provider-"
envJira = "JIRA_API_TOKEN"
envVersion = "VERSION_NUMBER"
projectKey = "CLOUDP"
jiraURL = "https://jira.mongodb.org"
versionPrefix = "terraform-provider-"
versionNameNext = "next-terraform-provider-release"
)

func main() {
client := getJiraClient()
versionName := versionPrefix + getVersion()
versionID := getVersionID(client, versionName)
moveDoneIssues(client, versionName)
setReleased(client, versionID)
url := fmt.Sprintf("%s/projects/%s/versions/%s", jiraURL, projectName, versionID)
url := fmt.Sprintf("%s/projects/%s/versions/%s", jiraURL, projectKey, versionID)
fmt.Printf("Version released, please check all tickets are marked as done: %s\n", url)
}

Expand Down Expand Up @@ -53,7 +55,7 @@ func getVersion() string {
func getVersionID(client *jira.Client, versionName string) string {
var projectID int
ctx := context.Background()
projects, _, err := client.Project.Get(ctx, projectName)
projects, _, err := client.Project.Get(ctx, projectKey)
if err != nil {
log.Fatalf("Error getting project info: %v", err)
}
Expand All @@ -75,6 +77,36 @@ func getVersionID(client *jira.Client, versionName string) string {
return version.ID
}

func moveDoneIssues(client *jira.Client, versionName string) {
jql := fmt.Sprintf("project = %s AND status in (Resolved, Closed) AND fixVersion = %s", projectKey, versionNameNext)
list, _, err := client.Issue.Search(context.Background(), jql, &jira.SearchOptions{MaxResults: 1000})
if err != nil {
log.Fatalf("Error retrieving issues: %v", err)
}
keys := make([]string, len(list))
for i := range list {
issue := &list[i]
keys[i] = issue.Key
moveIssue(client, issue.Key, versionName)
}
if len(keys) > 0 {
fmt.Println("Done issues moved:", strings.Join(keys, ", "))
}
}

func moveIssue(client *jira.Client, issueKey, versionName string) {
issue := &jira.Issue{
Key: issueKey,
Fields: &jira.IssueFields{
FixVersions: []*jira.FixVersion{{Name: versionName}},
},
}
_, _, err := client.Issue.Update(context.Background(), issue, nil)
if err != nil {
log.Fatalf("Error moving issue %s: %v", issueKey, err)
}
}

func setReleased(client *jira.Client, versionID string) {
version := &jira.Version{
ID: versionID,
Expand Down

0 comments on commit 12d6bf8

Please sign in to comment.