Skip to content

Commit

Permalink
♻️ Merge pull request #35 from HidemaruOwO/feature/commit-message-length
Browse files Browse the repository at this point in the history
✨ コミットメッセージに含まれるFilePathの長さが指定された長さを超えたらトリミングするように変更
  • Loading branch information
HidemaruOwO authored Aug 26, 2024
2 parents 3d166bd + 1e74b49 commit ef0d713
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/cmd/alias/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func AliasAddCmd(alias string, prefix string) {
}

func aliasAdd(alias string, prefix string) {
aliases := lib.GetAlias()
aliases := lib.GetAppConfig()

if alias != strings.TrimSpace(alias) || prefix != strings.TrimSpace(prefix) {
log.Warnf("Please do not include spaces in alias and emoji prefixes\n")
Expand Down Expand Up @@ -43,7 +43,7 @@ func aliasAdd(alias string, prefix string) {
os.Exit(0)
}

aliases.Alias = append(aliases.Alias, []string{alias, prefix, emoji})
*aliases.Alias = append(*aliases.Alias, []string{alias, prefix, emoji})

lib.WriteConfig(aliases)
log.Infof(
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/alias/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func AliasDeleteCmd(targets []string) {
}

func aliasDelete(targets []string) {
alias := lib.GetAlias()
slice := alias.Alias
alias := lib.GetAppConfig()
slice := *alias.Alias

log.Debugf(config.IS_DEBUG, "Removing %v\n", targets)

Expand All @@ -29,7 +29,7 @@ func aliasDelete(targets []string) {
}
wg.Wait()

alias.Alias = slice
*alias.Alias = slice
lib.WriteConfig(alias)
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/alias/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func aliasReset() {

input = strings.TrimSpace(input)
if input == "y" || input == "Y" {
var alias lib.Alias
var alias lib.AppConfig
if err := json.Unmarshal([]byte(config.BASE_JSON_DATA), &alias); err != nil {
log.Criticalf("JSON encoding failed\n")
log.ErrorExit(err)
Expand Down
23 changes: 16 additions & 7 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,35 @@ func gitCommit(prefix string, subject string) {
wg.Wait()

_, emoji := lib.IncludeGitimoji(prefix)
appConfig := lib.GetAppConfig()

aliases := lib.GetAlias()
gitChange = strings.ReplaceAll(gitChange, "\n", ", ")

var commitMsg string
var commigMessage string

if aliases.WriteEmoji {
var message string

if *appConfig.WriteEmoji {
if emoji != "" {
prefix = emoji
commitMsg = fmt.Sprintf("%s %s (%s)", prefix, subject, gitChange)
} else {
commitMsg = fmt.Sprintf(":%s: %s (%s)", prefix, subject, gitChange)
prefix = fmt.Sprintf(":%s:", prefix)
}
}

if *appConfig.UseLimitPathesLength {
if *appConfig.LimitPathesLength < len([]rune(gitChange)) {
gitChange = fmt.Sprintf("%s...", gitChange[:*appConfig.LimitPathesLength])
}

message = fmt.Sprintf("%s (%s)", subject, gitChange)
} else {
commitMsg = fmt.Sprintf(":%s: %s (%s)", prefix, subject, gitChange)
message = fmt.Sprintf("%s", subject)

Check failure on line 91 in src/cmd/root.go

View workflow job for this annotation

GitHub Actions / format

S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
}

cmd := exec.Command("git", "commit", "-m", commitMsg)
commigMessage = fmt.Sprintf("%s %s", prefix, message)

cmd := exec.Command("git", "commit", "-m", commigMessage)
_, err = cmd.Output()
if err != nil {
log.ErrorExit(err)
Expand Down
3 changes: 2 additions & 1 deletion src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"github.com/HidemaruOwO/nuts/log"
)

const VERSION string = "v1.2.3"
const VERSION string = "v1.2.4"

// const BaseJsonData string = `{
const BASE_JSON_DATA string = `{
"writeEmoji": true,
"useAlias": true,
"useLimitPathesLength": 50,
"alias": [
["s", "sparkles", "✨"],
["t", "tada", "🎉"],
Expand Down
73 changes: 56 additions & 17 deletions src/lib/config-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ type Gitmojis struct {
Name string `json:"name"`
Semver string `json:"semver"`
}
type Alias struct {
WriteEmoji bool `json:"writeEmoji"`
UseAlias bool `json:"useAlias"`
Alias [][]string `json:"alias"`
type AppConfig struct {
WriteEmoji *bool `json:"writeEmoji"`
UseAlias *bool `json:"useAlias"`
UseLimitPathesLength *bool `json:"useLimitPathesLength"`
LimitPathesLength *int `json:"limitPathesLength"`
Alias *[][]string `json:"alias"`
}

func Init(path string) {
Expand Down Expand Up @@ -61,13 +63,13 @@ func Init(path string) {
log.Debugf(config.IS_DEBUG, "Create gitimoji.json\n")
store.Save("gitimoji.json", gitmoji)

Check failure on line 64 in src/lib/config-manager.go

View workflow job for this annotation

GitHub Actions / format

Error return value of `store.Save` is not checked (errcheck)

var alias Alias
if err := json.Unmarshal([]byte(config.BASE_JSON_DATA), &alias); err != nil {
var appConfig AppConfig
if err := json.Unmarshal([]byte(config.BASE_JSON_DATA), &appConfig); err != nil {
log.Criticalf("JSON encoding failed\n")
log.ErrorExit(err)
}
log.Debugf(config.IS_DEBUG, "Create config.json\n")
store.Save("config.json", alias)
store.Save("config.json", appConfig)

Check failure on line 72 in src/lib/config-manager.go

View workflow job for this annotation

GitHub Actions / format

Error return value of `store.Save` is not checked (errcheck)
}
}

Expand All @@ -81,33 +83,70 @@ func GetGitmoji() Gitmoji {
return gitimoji
}

func GetAlias() Alias {
var alias Alias
func GetAppConfig() AppConfig {
var appConfig AppConfig
store.SetApplicationName("pummit")
if err := store.Load("config.json", &alias); err != nil {
if err := store.Load("config.json", &appConfig); err != nil {
log.Criticalf("Loading alias list failed\n")
log.ErrorExit(err)
}
return alias
checkConfig(appConfig)
return appConfig
}

func GetAliasList() [][]string {
var alias Alias
func resetConfig() {

Check failure on line 97 in src/lib/config-manager.go

View workflow job for this annotation

GitHub Actions / format

func `resetConfig` is unused (unused)
var appConfig AppConfig
store.SetApplicationName("pummit")
if err := store.Load("config.json", &alias); err != nil {
log.Criticalf("Loading alias list failed\n")
if err := json.Unmarshal([]byte(config.BASE_JSON_DATA), &appConfig); err != nil {
log.Criticalf("JSON encoding failed\n")
log.ErrorExit(err)
}
log.Debugf(config.IS_DEBUG, "Reset config.json\n")
if err := store.Save("config.json", appConfig); err != nil {
log.ErrorExit(err)
}
return alias.Alias
}

func WriteConfig(configData Alias) {
func GetAliasList() [][]string {
var config = GetAppConfig()
return *config.Alias
}

func WriteConfig(configData AppConfig) {
store.SetApplicationName("pummit")
if err := store.Save("config.json", configData); err != nil {
log.ErrorExit(err)
}
}

// configの値が正常が見るわ!
func checkConfig(appConfig AppConfig) {
log.Debugf(config.IS_DEBUG, "%+v\n", appConfig)
// TODO configにプロパティを追加する度に書く必要があるわ!
if appConfig.UseAlias == nil {
defaultValue := true
appConfig.UseAlias = &defaultValue
}
if appConfig.WriteEmoji == nil {
defaultValue := true
appConfig.WriteEmoji = &defaultValue
}
if appConfig.UseLimitPathesLength == nil {
defaultValue := true
appConfig.UseLimitPathesLength = &defaultValue
}
if appConfig.LimitPathesLength == nil {
defaultValue := 50
appConfig.LimitPathesLength = &defaultValue
}
if appConfig.Alias == nil {
defaultValue := [][]string{}
appConfig.Alias = &defaultValue
}

WriteConfig(appConfig)
}

func PlatformPath(path string) string {
if runtime.GOOS == "windows" {
return fmt.Sprintf("%s\\%s", os.Getenv("APPDATA"), path)
Expand Down

0 comments on commit ef0d713

Please sign in to comment.