As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 1bade9e1 authored by Ash McKenzie's avatar Ash McKenzie Committed by Igor Drozdov
Browse files

More consistent console messages (golang)

parent 412ed17c
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -7,6 +7,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/internal/command"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/executable"
)
Loading
Loading
@@ -38,7 +39,7 @@ func main() {
}
if err = cmd.Execute(); err != nil {
fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
console.DisplayWarningMessage(err.Error(), readWriter.ErrOut)
os.Exit(1)
}
}
Loading
Loading
@@ -7,6 +7,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/internal/command"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/executable"
)
Loading
Loading
@@ -38,7 +39,7 @@ func main() {
}
if err = cmd.Execute(); err != nil {
fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
console.DisplayWarningMessage(err.Error(), readWriter.ErrOut)
os.Exit(1)
}
}
Loading
Loading
@@ -7,6 +7,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/internal/command"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/executable"
)
Loading
Loading
@@ -38,7 +39,7 @@ func main() {
}
if err = cmd.Execute(); err != nil {
fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
console.DisplayWarningMessage(err.Error(), readWriter.ErrOut)
os.Exit(1)
}
}
Loading
Loading
@@ -31,12 +31,12 @@ func TestFailedRequests(t *testing.T) {
{
desc: "With missing arguments",
arguments: &commandargs.Shell{},
expectedOutput: "> GitLab: Disallowed command",
expectedOutput: "Disallowed command",
},
{
desc: "With disallowed command",
arguments: &commandargs.Shell{GitlabKeyId: "1", SshArgs: []string{"git-lfs-authenticate", "group/repo", "unknown"}},
expectedOutput: "> GitLab: Disallowed command",
expectedOutput: "Disallowed command",
},
{
desc: "With disallowed user",
Loading
Loading
Loading
Loading
@@ -3,12 +3,13 @@ package receivepack
import (
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
"gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet"
"gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/accessverifier"
)
Loading
Loading
@@ -32,19 +33,11 @@ func (c *Command) processCustomAction(response *accessverifier.Response) error {
return errors.New("Custom action error: Empty API endpoints")
}
c.displayInfoMessage(data.InfoMessage)
console.DisplayInfoMessages(strings.Split(data.InfoMessage, "\n"), c.ReadWriter.ErrOut)
return c.processApiEndpoints(response)
}
func (c *Command) displayInfoMessage(infoMessage string) {
messages := strings.Split(infoMessage, "\n")
for _, msg := range messages {
fmt.Fprintf(c.ReadWriter.ErrOut, "> GitLab: %v\n", msg)
}
}
func (c *Command) processApiEndpoints(response *accessverifier.Response) error {
client, err := gitlabnet.GetClient(c.Config)
Loading
Loading
Loading
Loading
@@ -100,6 +100,6 @@ func TestCustomReceivePack(t *testing.T) {
// expect printing of info message, "custom" string from the first request
// and "output" string from the second request
require.Equal(t, "> GitLab: info_message\n> GitLab: one more message\n", errBuf.String())
require.Equal(t, "remote: \nremote: info_message\nremote: one more message\nremote: \n", errBuf.String())
require.Equal(t, "customoutput", outBuf.String())
}
Loading
Loading
@@ -2,11 +2,11 @@ package accessverifier
import (
"errors"
"fmt"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/accessverifier"
)
Loading
Loading
@@ -39,7 +39,5 @@ func (c *Command) Verify(action commandargs.CommandType, repo string) (*Response
}
func (c *Command) displayConsoleMessages(messages []string) {
for _, msg := range messages {
fmt.Fprintf(c.ReadWriter.ErrOut, "> GitLab: %v\n", msg)
}
console.DisplayInfoMessages(messages, c.ReadWriter.ErrOut)
}
Loading
Loading
@@ -77,6 +77,6 @@ func TestConsoleMessages(t *testing.T) {
cmd.Args = &commandargs.Shell{GitlabKeyId: "1"}
cmd.Verify(action, repo)
require.Equal(t, "> GitLab: console\n> GitLab: message\n", errBuf.String())
require.Equal(t, "remote: \nremote: console\nremote: message\nremote: \n", errBuf.String())
require.Empty(t, outBuf.String())
}
Loading
Loading
@@ -3,5 +3,5 @@ package disallowedcommand
import "errors"
var (
Error = errors.New("> GitLab: Disallowed command")
Error = errors.New("Disallowed command")
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment