-
Notifications
You must be signed in to change notification settings - Fork 210
Enable to make git URLs #594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
pkg/app/piped/trigger/deployment.go
Outdated
|
|
||
| func buildDeploment(app *model.Application, branch string, commit git.Commit, commander string, now time.Time) (*model.Deployment, error) { | ||
| func buildDeployment(app *model.Application, branch string, commit git.Commit, commander string, now time.Time) (*model.Deployment, error) { | ||
| commitURL, err := git.MakeCommitURL(app.GitPath.Repo.Remote, commit.Hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Panic could be occurred because old Applications don't have Repo.
But proto validate ensures that Repo is populated, so I keep this implementation.
https://github.com/pipe-cd/pipe/blob/af263d98e824fd97f5b5e22934f1e188c8f32608/pkg/model/common.proto#L32
|
Code coverage for golang is
|
pkg/git/url.go
Outdated
| case "bitbucket.org": | ||
| subPath = "commits" | ||
| default: | ||
| return "", fmt.Errorf("unsupported git host: %q", u.Host) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about GHE where its host could be customized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... actually I'm still debating for it.
For now, I'm wondering if "commit" is applied for all of unsupported hosts.
switch u.Host {
case "github.com", "gitlab.com":
subPath = "commit"
case "bitbucket.org":
subPath = "commits"
default:
subPath = "commit"
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is ok to apply this way at this time. In the future, we can allow the user to specify those fields from Web UI while registering the application.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, gonna do so.
pkg/git/url_test.go
Outdated
| }) | ||
| } | ||
| } | ||
| func Test_parseGitURL(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: TestParseGitURL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intellij IDEA generates this name (maybe to distinguish between public ParseGitURL and private)...
But a bit gross, fix it.
pkg/app/api/api/web_api.go
Outdated
| return &webservice.AddApplicationResponse{}, nil | ||
| } | ||
|
|
||
| // Adds Repository info and then makes the GitPath URL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "makeGitPath ..."
pkg/app/api/api/web_api.go
Outdated
|
|
||
| // Adds Repository info and then makes the GitPath URL. | ||
| func (a *WebAPI) makeGitPath(ctx context.Context, repoID, path, cfgFilename, pipedID string) (*model.ApplicationGitPath, error) { | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Remove empty line.
pkg/app/api/api/web_api.go
Outdated
| } | ||
| u, err := git.MakeDirURL(repo.Remote, path, repo.Branch) | ||
| if err != nil { | ||
| return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return a gRPC error. This should error be logged and then return an internal error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're quite right.
| "ftp": struct{}{}, | ||
| "ftps": struct{}{}, | ||
| "rsync": struct{}{}, | ||
| "file": struct{}{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://git-scm.com/docs/git-clone#_git_urls
Git supports ssh, git, http, and https protocols (in addition, ftp, and ftps can be used for fetching, but this is inefficient and deprecated; do not use it).
Because ftp and other protocols were deprecated, so we only need to support ssh, git, http[s].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I was not sure that. Thanks.
| } | ||
|
|
||
| func buildDeploment(app *model.Application, branch string, commit git.Commit, commander string, now time.Time) (*model.Deployment, error) { | ||
| func buildDeployment(app *model.Application, branch string, commit git.Commit, commander string, now time.Time) (*model.Deployment, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better than panic, let's add a check for the existence of Repo field and return an error if it was nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of returning an error, I decided to ignore if it's nil
pkg/app/api/api/web_api.go
Outdated
| if err != nil { | ||
| return nil, err | ||
| } | ||
| repo := &model.ApplicationGitRepository{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var repo *model.ApplicationGitRepository
and return an error when the repository was not found.
|
Code coverage for golang is
|
pkg/git/url_test.go
Outdated
| func TestParseGitURL(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| rawurl string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rawURL
pkg/git/url_test.go
Outdated
| tests := []struct { | ||
| name string | ||
| rawurl string | ||
| wantU *url.URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: wantURL
| if !reflect.DeepEqual(gotU, tt.wantU) { | ||
| t.Errorf("parseGitURL() got = %#v, want %#v", gotU, tt.wantU) | ||
| } | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using testify for testing so let's use its functions to unify the code.
assert.Equal(t, tc.expectedURL, gotURL)
assert.Equal(t, tc.exepcetedErr, err)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
|
LGTM |
|
The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use Details1. Allow users to specify git hostThis was created by todo plugin since "TODO:" was found in b023edf when #594 was merged. cc: @nakabonne.2. Support more git hostThis was created by todo plugin since "TODO:" was found in b023edf when #594 was merged. cc: @nakabonne.3. Allow users to specify git hostThis was created by todo plugin since "TODO:" was found in b023edf when #594 was merged. cc: @nakabonne. |
|
Code coverage for golang is
|
|
Fixed |
|
Thank you. |
What this PR does / why we need it:
This PR does:
MakeDirURLwhen adding an ApplicationMakeCommitURLwhen building a DeploymentWhich issue(s) this PR fixes:
Fixes #414
Does this PR introduce a user-facing change?: