From 7dde83494dfd90c99ee3d45856507f1f17108a31 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Wed, 3 Jul 2024 12:57:46 +0100 Subject: [PATCH 1/2] Refactor submission creation in submit.go and test.go This commit refactors the submission creation in submit.go and test.go files. It adds a new parameter command to the CreateSubmission function in codecrafters_client.go file. The command parameter is used to specify the type of submission, either "submit" or "test". This change allows for better code organization and separation of concerns. Commit message: "Refactor submission creation in submit.go and test.go" --- internal/commands/submit.go | 2 +- internal/commands/test.go | 2 +- internal/utils/codecrafters_client.go | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/commands/submit.go b/internal/commands/submit.go index 02d4c19..9dc3840 100644 --- a/internal/commands/submit.go +++ b/internal/commands/submit.go @@ -91,7 +91,7 @@ func SubmitCommand(ctx context.Context) (err error) { logger.Debug().Msgf("creating submission for %s", commitSha) - createSubmissionResponse, err := codecraftersClient.CreateSubmission(codecraftersRemote.CodecraftersRepositoryId(), commitSha) + createSubmissionResponse, err := codecraftersClient.CreateSubmission(codecraftersRemote.CodecraftersRepositoryId(), commitSha, "submit") if err != nil { return fmt.Errorf("create submission: %w", err) } diff --git a/internal/commands/test.go b/internal/commands/test.go index 507b0ef..ac351bc 100644 --- a/internal/commands/test.go +++ b/internal/commands/test.go @@ -105,7 +105,7 @@ func TestCommand(ctx context.Context) (err error) { logger.Debug().Msgf("creating submission for %s", tempCommitSha) - createSubmissionResponse, err := codecraftersClient.CreateSubmission(codecraftersRemote.CodecraftersRepositoryId(), tempCommitSha) + createSubmissionResponse, err := codecraftersClient.CreateSubmission(codecraftersRemote.CodecraftersRepositoryId(), tempCommitSha, "test") if err != nil { return fmt.Errorf("create submission: %w", err) } diff --git a/internal/utils/codecrafters_client.go b/internal/utils/codecrafters_client.go index 0005fd6..4c016fc 100644 --- a/internal/utils/codecrafters_client.go +++ b/internal/utils/codecrafters_client.go @@ -88,12 +88,12 @@ func (c CodecraftersClient) headers() map[string]string { } } -func (c CodecraftersClient) CreateSubmission(repositoryId string, commitSha string) (CreateSubmissionResponse, error) { +func (c CodecraftersClient) CreateSubmission(repositoryId string, commitSha string, command string) (CreateSubmissionResponse, error) { response, err := grequests.Post(c.ServerUrl+"/services/cli/create_submission", &grequests.RequestOptions{ JSON: map[string]interface{}{ - "repository_id": repositoryId, - "commit_sha": commitSha, - "should_auto_advance": false, + "repository_id": repositoryId, + "commit_sha": commitSha, + "command": command, }, Headers: c.headers(), }) From d9d7c00ccce3a447cad81b8a4f8ac7e385c7eaae Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Wed, 3 Jul 2024 12:58:47 +0100 Subject: [PATCH 2/2] Update CODECRAFTERS_CLI_VERSION to v31 in install.sh --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index b7d56fb..49c0b86 100644 --- a/install.sh +++ b/install.sh @@ -3,7 +3,7 @@ set -eu # allow overriding the version -VERSION=${CODECRAFTERS_CLI_VERSION:-v30} +VERSION=${CODECRAFTERS_CLI_VERSION:-v31} PLATFORM=$(uname -s) ARCH=$(uname -m)