Skip to content

Commit 258edf7

Browse files
authored
Merge pull request #39 from eksrvb/feature/create-major-version-via-comment
create major version via comment
2 parents 048a47c + 3d863af commit 258edf7

File tree

5 files changed

+74
-1
lines changed

5 files changed

+74
-1
lines changed

gitOnlineController/gitOnlineController.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ func GetPrNumberForBranch(branch string) int {
1313
return 0
1414
}
1515

16+
func GetIssueComments(issueNumber int) (issueComments []models.GitHubIssueComment, err error) {
17+
switch CiEnvironment.GitType {
18+
case "github":
19+
issueComments, err = github_getIssueComments(issueNumber)
20+
}
21+
return
22+
}
23+
1624
// GetPrNumberForBranch
1725
func GetPrInfos(prNumber int) (prInfos models.GitHubPullRequest, err error) {
1826
switch CiEnvironment.GitType {

gitOnlineController/github.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ func github_getPrInfos(prNumber int) (prInfos models.GitHubPullRequest, err erro
3535
return
3636
}
3737

38+
func github_getIssueComments(issueNumber int) (issueComments []models.GitHubIssueComment, err error) {
39+
url := fmt.Sprintf("%srepos/%s/issues/%d/comments", CiEnvironment.GitInfos.ApiUrl, CiEnvironment.GitInfos.FullRepo, issueNumber)
40+
respBytes := newGitHubGetRequestUnmapped(url)
41+
err = json.Unmarshal(respBytes, &issueComments)
42+
return
43+
}
44+
3845
func github_getLatestReleaseVersion() string {
3946
url := fmt.Sprintf("%srepos/%s/releases/latest", CiEnvironment.GitInfos.ApiUrl, CiEnvironment.GitInfos.FullRepo)
4047
result := newGitHubGetRequest(url, CiEnvironment.GitInfos.ApiToken)

models/github.models.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,39 @@ type GithubReposRepoPull struct {
1717
Number int `json:"number"`
1818
}
1919

20+
type GitHubIssueComment struct {
21+
URL string `json:"url"`
22+
HTMLURL string `json:"html_url"`
23+
IssueURL string `json:"issue_url"`
24+
ID int `json:"id"`
25+
NodeID string `json:"node_id"`
26+
User struct {
27+
Login string `json:"login"`
28+
ID int `json:"id"`
29+
NodeID string `json:"node_id"`
30+
AvatarURL string `json:"avatar_url"`
31+
GravatarID string `json:"gravatar_id"`
32+
URL string `json:"url"`
33+
HTMLURL string `json:"html_url"`
34+
FollowersURL string `json:"followers_url"`
35+
FollowingURL string `json:"following_url"`
36+
GistsURL string `json:"gists_url"`
37+
StarredURL string `json:"starred_url"`
38+
SubscriptionsURL string `json:"subscriptions_url"`
39+
OrganizationsURL string `json:"organizations_url"`
40+
ReposURL string `json:"repos_url"`
41+
EventsURL string `json:"events_url"`
42+
ReceivedEventsURL string `json:"received_events_url"`
43+
Type string `json:"type"`
44+
SiteAdmin bool `json:"site_admin"`
45+
} `json:"user"`
46+
CreatedAt time.Time `json:"created_at"`
47+
UpdatedAt time.Time `json:"updated_at"`
48+
AuthorAssociation string `json:"author_association"`
49+
Body string `json:"body"`
50+
PerformedViaGithubApp interface{} `json:"performed_via_github_app"`
51+
}
52+
2053
type GitHubPullRequest struct {
2154
URL string `json:"url"`
2255
ID int `json:"id"`

service/createRelease.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func CreateRelease(cienv string, versionOverr *string, patchLevelOverr *string, isDryRun *bool, preRelease *bool, publishNpm *string, uploadArtifacts *string) {
1414

15-
prInfos, _, err := getPRInfos()
15+
prInfos, prNumber, err := getPRInfos()
1616
if err != nil {
1717
panic(err)
1818
}
@@ -24,6 +24,11 @@ func CreateRelease(cienv string, versionOverr *string, patchLevelOverr *string,
2424
patchLevel = *patchLevelOverr
2525
}
2626

27+
// if an comment exists with aci=major, make a major version!
28+
if detectIfMajor(prNumber) {
29+
patchLevel = "major"
30+
}
31+
2732
var gitVersion string
2833
if *versionOverr != "" {
2934
gitVersion = *versionOverr

service/getBuildInfos.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ func GetBuildInfos(cienv string, versionOverr *string, patchLevelOverr *string,
2121
branchName := prInfos.Head.Ref
2222
patchLevel := branchName[:strings.Index(branchName, "/")]
2323

24+
// if an comment exists with aci=major, make a major version!
25+
if detectIfMajor(prNumber) {
26+
patchLevel = "major"
27+
}
28+
2429
if *patchLevelOverr != "" {
2530
patchLevel = *patchLevelOverr
2631
}
@@ -129,3 +134,18 @@ func getNameRevHead() (pr int, branchName string, err error) {
129134
}
130135
return
131136
}
137+
138+
func detectIfMajor(issueNumber int) bool {
139+
resBool := false
140+
issueComments, err := gitOnlineController.GetIssueComments(issueNumber)
141+
if err != nil {
142+
panic(err)
143+
}
144+
for _, comment := range issueComments {
145+
if strings.Contains(comment.Body, "aci=major") {
146+
resBool = true
147+
break
148+
}
149+
}
150+
return resBool
151+
}

0 commit comments

Comments
 (0)