-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
161 lines (123 loc) · 3.65 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"regexp"
"time"
"github.com/actions-go/toolkit/core"
)
var domain, project, version, token string
var isCreateNextVersion bool
type ValueType struct {
Self string `json:"self"`
Id string `json:"id"`
Description string `json:"description"`
Name string `json:"name"`
Archived bool `json:"archived"`
Released bool `json:"released"`
StartDate string `json:"startDate"`
ReleaseDate string `json:"releaseDate"`
Overdue bool `json:"overdue"`
UserStartDate string `json:"userStartDate"`
UserReleaseDate string `json:"userReleaseDate"`
ProjectId int `json:"projectId"`
}
type VersionType struct {
Self string `json:"self"`
MaxResults int `json:"maxResults"`
StartAt int `json:"startAt"`
Total int `json:"total"`
IsLast bool `json:"isLast"`
Values []ValueType `json:"values"`
}
func getVersionName(version string) string {
r, _ := regexp.Compile(".*(\\d{1,5}\\.\\d{1,5}\\.\\d{1,5})")
var match = r.FindStringSubmatch(version)
if match == nil || len(match) < 1 {
return ""
}
return match[0]
}
// func getVersions(appName, domain, project, token string) bool {
// }
type PostBody struct {
Released bool `json:"released"`
ReleaseDate string `json:"releaseDate"`
}
func releaseVersion(versionId string) {
fmt.Println(versionId)
fmt.Println("Trying release version")
reqBody := PostBody{
Released: true,
ReleaseDate: time.Now().String()[:10],
}
rBytes, _ := json.Marshal(reqBody)
buff := bytes.NewBuffer(rBytes)
releaseUri := `https://drivingteacher.atlassian.net/rest/api/3/version/` + versionId
fmt.Println(releaseUri, reqBody, rBytes, buff)
req, err := http.NewRequest("PUT", releaseUri, buff)
if err != nil {
panic(err)
}
req.Header.Add("Content-Type", "application/json")
releaseClient := &http.Client{}
resp, clientErr := releaseClient.Do(req)
if clientErr != nil {
fmt.Println("Error")
panic(clientErr)
}
defer resp.Body.Close()
bytes, _ := io.ReadAll(resp.Body)
str := string(bytes) //바이트를 문자열로
var dat VersionType
if err := json.Unmarshal([]byte(str), &dat); err != nil {
panic(err)
}
fmt.Println(dat)
fmt.Println("Version Release Succeded")
}
func main() {
domain, _ := core.GetInput("domain")
project, _ := core.GetInput("project")
releaseName, _ := core.GetInput("releaseName")
token, _ := core.GetInput("auth-token")
// isCreateNextVersion := core.GetBoolInput("create-next-version")
// versionName := getVersionName(version)
// if len(version) < 1 {
// core.SetFailed("Version is Not correct.")
// return
// }
// appName := strings.Replace(version, versionName, "", -1)
// println(`appName: `, appName, `versionName: `, versionName)
// getVerson
uri := `https://` + domain + `.atlassian.net/rest/api/3/project/` + project + `/version?query=` + url.QueryEscape(releaseName) + `&orderBy=name&status=unreleased`
req, err := http.NewRequest("GET", uri, nil)
if err != nil {
panic(err)
}
req.Header.Add("Authorization", `Basic `+token)
client := &http.Client{}
resp, clientErr := client.Do(req)
if clientErr != nil {
panic(clientErr)
}
defer resp.Body.Close()
bytes, _ := io.ReadAll(resp.Body)
str := string(bytes) //바이트를 문자열로
var dat VersionType
if err := json.Unmarshal([]byte(str), &dat); err != nil {
panic(err)
}
var currentVersion string
for _, v := range dat.Values {
if v.Name == "DT test" {
currentVersion = v.Name
}
}
fmt.Println(dat.IsLast, dat.Values[0].Id, currentVersion)
// releaseVersion(dat.Values[0].Id)
}