Skip to content

Commit

Permalink
add logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
mo3et committed Oct 22, 2024
1 parent 54a6a12 commit 7277ed1
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tools/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import (
"strings"
)

// You can specify a tag as a command line argument to generate the changelog for a specific version.
// Example: go run tools/changelog.go v0.0.33
// If no tag is provided, the latest release will be used.

// Setting repo owner and repo name by generate changelog
const (
repoOwner = "openimsdk"
repoName = "actions-test"
)

// GitHubRepo struct represents the repo details.
type GitHubRepo struct {
Owner string
Expand All @@ -32,6 +42,7 @@ func (g *GitHubRepo) classifyReleaseNotes(body string) map[string][]string {
"fix": {},
"chore": {},
"refactor": {},
"build": {},
"other": {},
}

Expand Down Expand Up @@ -64,6 +75,8 @@ func (g *GitHubRepo) classifyReleaseNotes(body string) map[string][]string {
category = "chore"
} else if strings.HasPrefix(line, "* refactor") {
category = "refactor"
} else if strings.HasPrefix(line, "* build") {
category = "build"
} else {
category = "other"
}
Expand Down Expand Up @@ -108,11 +121,13 @@ func (g *GitHubRepo) generateChangelog(tag, date, htmlURL, body string) string {
if len(sections["refactor"]) > 0 {
changelog += "### Refactors\n" + strings.Join(sections["refactor"], "\n") + "\n\n"
}
if len(sections["build"]) > 0 {
changelog += "### Builds\n" + strings.Join(sections["build"], "\n") + "\n\n"
}
if len(sections["other"]) > 0 {
changelog += "### Others\n" + strings.Join(sections["other"], "\n") + "\n\n"
}

// Add the Full Changelog link at the end, if available.
if g.FullChangelog != "" {
changelog += fmt.Sprintf("**Full Changelog**: %s\n", g.FullChangelog)
}
Expand Down Expand Up @@ -153,13 +168,11 @@ func (g *GitHubRepo) fetchReleaseData(version string) (*ReleaseData, error) {
}

func main() {
// Create a new GitHubRepo instance
repoOwner := "openimsdk"
repoName := "actions-test"
repo := &GitHubRepo{Owner: repoOwner, Repo: repoName}

// Get the version from command line arguments, if provided
var version string
var version string // Default is use latest

if len(os.Args) > 1 {
version = os.Args[1] // Use the provided version
}
Expand Down

0 comments on commit 7277ed1

Please sign in to comment.