Skip to content

Commit

Permalink
Merge pull request #2769 from ActiveState/mitchell/dx-2031
Browse files Browse the repository at this point in the history
Construct commit messages for requirement changes.
  • Loading branch information
mitchell-as authored Sep 26, 2023
2 parents 99bbe2f + 20a2eac commit 5ea71d1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 63 deletions.
60 changes: 60 additions & 0 deletions internal/runbits/requirements/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"strconv"
"strings"

"github.com/ActiveState/cli/internal/analytics"
Expand Down Expand Up @@ -242,6 +243,7 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ
Owner: pj.Owner(),
Project: pj.Name(),
ParentCommit: string(parentCommitID),
Description: commitMessage(operation, name, version, ns, requirementBitWidth),
RequirementName: name,
RequirementVersion: requirements,
RequirementNamespace: ns,
Expand Down Expand Up @@ -418,3 +420,61 @@ func initializeProject() (*project.Project, error) {

return project.FromPath(target)
}

func commitMessage(op bpModel.Operation, name, version string, namespace model.Namespace, word int) string {
switch namespace.Type() {
case model.NamespaceLanguage:
return languageCommitMessage(op, name, version)
case model.NamespacePlatform:
return platformCommitMessage(op, name, version, word)
case model.NamespacePackage, model.NamespaceBundle:
return packageCommitMessage(op, name, version)
}

return ""
}

func languageCommitMessage(op bpModel.Operation, name, version string) string {
var msgL10nKey string
switch op {
case bpModel.OperationAdded:
msgL10nKey = "commit_message_added_language"
case bpModel.OperationUpdated:
msgL10nKey = "commit_message_updated_language"
case bpModel.OperationRemoved:
msgL10nKey = "commit_message_removed_language"
}

return locale.Tr(msgL10nKey, name, version)
}

func platformCommitMessage(op bpModel.Operation, name, version string, word int) string {
var msgL10nKey string
switch op {
case bpModel.OperationAdded:
msgL10nKey = "commit_message_added_platform"
case bpModel.OperationUpdated:
msgL10nKey = "commit_message_updated_platform"
case bpModel.OperationRemoved:
msgL10nKey = "commit_message_removed_platform"
}

return locale.Tr(msgL10nKey, name, strconv.Itoa(word), version)
}

func packageCommitMessage(op bpModel.Operation, name, version string) string {
var msgL10nKey string
switch op {
case bpModel.OperationAdded:
msgL10nKey = "commit_message_added_package"
case bpModel.OperationUpdated:
msgL10nKey = "commit_message_updated_package"
case bpModel.OperationRemoved:
msgL10nKey = "commit_message_removed_package"
}

if version == "" {
version = locale.Tl("package_version_auto", "auto")
}
return locale.Tr(msgL10nKey, name, version)
}
7 changes: 4 additions & 3 deletions pkg/platform/api/buildplanner/request/stagecommit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package request

import "github.com/ActiveState/cli/pkg/platform/runtime/buildexpression"

func StageCommit(owner, project, parentCommit string, expression *buildexpression.BuildExpression) *buildPlanByStageCommit {
func StageCommit(owner, project, parentCommit, description string, expression *buildexpression.BuildExpression) *buildPlanByStageCommit {
return &buildPlanByStageCommit{map[string]interface{}{
"organization": owner,
"project": project,
"parentCommit": parentCommit,
"description": description,
"expr": expression,
}}
}
Expand All @@ -17,8 +18,8 @@ type buildPlanByStageCommit struct {

func (b *buildPlanByStageCommit) Query() string {
return `
mutation ($organization: String!, $project: String!, $parentCommit: ID, $expr:BuildExpr!) {
stageCommit(input:{organization:$organization, project:$project, parentCommitId:$parentCommit, expr:$expr}) {
mutation ($organization: String!, $project: String!, $parentCommit: ID, $description: String!, $expr:BuildExpr!) {
stageCommit(input:{organization:$organization, project:$project, parentCommitId:$parentCommit, description:$description, expr:$expr}) {
... on Commit {
__typename
expr
Expand Down
3 changes: 2 additions & 1 deletion pkg/platform/model/buildplanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ type StageCommitParams struct {
Owner string
Project string
ParentCommit string
Description string
// Commits can have either an operation (e.g. installing a package)...
RequirementName string
RequirementVersion []bpModel.VersionRequirement
Expand Down Expand Up @@ -290,7 +291,7 @@ func (bp *BuildPlanner) StageCommit(params StageCommitParams) (strfmt.UUID, erro
}

// With the updated build expression call the stage commit mutation
request := request.StageCommit(params.Owner, params.Project, params.ParentCommit, expression)
request := request.StageCommit(params.Owner, params.Project, params.ParentCommit, params.Description, expression)
resp := &bpModel.StageCommitResult{}
err := bp.client.Run(request, resp)
if err != nil {
Expand Down
59 changes: 0 additions & 59 deletions pkg/platform/model/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"regexp"
"strconv"
"strings"

"github.com/ActiveState/cli/internal/constants"
Expand Down Expand Up @@ -668,64 +667,6 @@ func (cs indexedCommits) countBetween(first, last string) (int, error) {
return ct, nil
}

func commitMessage(op Operation, name, version string, namespace Namespace, word int) string {
switch namespace.Type() {
case NamespaceLanguage:
return languageCommitMessage(op, name, version)
case NamespacePlatform:
return platformCommitMessage(op, name, version, word)
case NamespacePackage, NamespaceBundle:
return packageCommitMessage(op, name, version)
}

return ""
}

func languageCommitMessage(op Operation, name, version string) string {
var msgL10nKey string
switch op {
case OperationAdded:
msgL10nKey = "commit_message_added_language"
case OperationUpdated:
msgL10nKey = "commit_message_updated_language"
case OperationRemoved:
msgL10nKey = "commit_message_removed_language"
}

return locale.Tr(msgL10nKey, name, version)
}

func platformCommitMessage(op Operation, name, version string, word int) string {
var msgL10nKey string
switch op {
case OperationAdded:
msgL10nKey = "commit_message_added_platform"
case OperationUpdated:
msgL10nKey = "commit_message_updated_platform"
case OperationRemoved:
msgL10nKey = "commit_message_removed_platform"
}

return locale.Tr(msgL10nKey, name, strconv.Itoa(word), version)
}

func packageCommitMessage(op Operation, name, version string) string {
var msgL10nKey string
switch op {
case OperationAdded:
msgL10nKey = "commit_message_added_package"
case OperationUpdated:
msgL10nKey = "commit_message_updated_package"
case OperationRemoved:
msgL10nKey = "commit_message_removed_package"
}

if version == "" {
version = locale.Tl("package_version_auto", "auto")
}
return locale.Tr(msgL10nKey, name, version)
}

func ResolveRequirementNameAndVersion(name, version string, word int, namespace Namespace) (string, string, error) {
if namespace.Type() == NamespacePlatform {
platform, err := FetchPlatformByDetails(name, version, word)
Expand Down

0 comments on commit 5ea71d1

Please sign in to comment.