-
Notifications
You must be signed in to change notification settings - Fork 110
fix: request license information from GitLab API #6593
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
base: main
Are you sure you want to change the base?
Changes from all commits
7622661
ba135e4
dd9935e
14914e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,7 +131,6 @@ | |
| }, | ||
| }, | ||
| { | ||
| name: "repository succeeds", | ||
| args: args{ | ||
| ctx: context.TODO(), | ||
| getByProps: properties.NewProperties(map[string]any{ | ||
|
|
@@ -143,19 +142,30 @@ | |
| properties.RepoPropertyIsPrivate: true, | ||
| properties.RepoPropertyIsArchived: false, | ||
| properties.RepoPropertyIsFork: false, | ||
| RepoPropertyLicense: "mit", // Uses the correct constant | ||
| }), | ||
| wantErr: false, | ||
| gitLabServerMockFunc: func(w http.ResponseWriter, _ *http.Request) { | ||
| gitLabServerMockFunc: func(w http.ResponseWriter, r *http.Request) { | ||
| // Verify the query parameter you added is being sent | ||
| if r.URL.Query().Get("license") != "true" { | ||
| t.Errorf("expected query param license=true, got %s", r.URL.RawQuery) | ||
| w.WriteHeader(http.StatusBadRequest) | ||
| return | ||
| } | ||
|
|
||
| resp := &gitlab.Project{ | ||
| ID: 1, | ||
| Name: "project-1", | ||
| Description: "project-1 description", | ||
| Visibility: gitlab.PrivateVisibility, | ||
| Archived: false, | ||
| ForkedFromProject: nil, | ||
| ID: 1, | ||
| Name: "project-1", | ||
| Description: "project-1 description", | ||
| Visibility: gitlab.PrivateVisibility, | ||
| Archived: false, | ||
| ForkedFromProject: nil, | ||
| Namespace: &gitlab.ProjectNamespace{ | ||
| Path: "group", | ||
| }, | ||
| License: &gitlab.ProjectLicense{ | ||
| Name: "mit", // Changed Key to Name to match repository_properties.go | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this comment make sense in 6 months? |
||
| }, | ||
| } | ||
|
|
||
| w.Header().Set("Content-Type", "application/json") | ||
|
|
@@ -397,3 +407,44 @@ | |
| cli: &http.Client{}, | ||
| } | ||
| } | ||
|
|
||
|
|
||
| func TestGitlabProjectToProperties_License(t *testing.T) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this test cover that the other test doesn't? In general, extra tests add maintenance burden when refactoring code. That burden pays off when the tests cover additional important code cases, but redundant tests add more maintenance cost without commensurate benefits. |
||
| t.Parallel() | ||
|
|
||
| // 1. Create a mock GitLab project with a license | ||
| mockProject := &gitlab.Project{ | ||
| ID: 123, | ||
| Name: "test-repo", | ||
| Namespace: &gitlab.ProjectNamespace{ | ||
| Path: "test-org", | ||
| }, | ||
| License: &gitlab.ProjectLicense{ | ||
| Name: "Apache-2.0", | ||
| }, | ||
| Visibility: gitlab.PublicVisibility, | ||
| Archived: false, | ||
| DefaultBranch: "main", | ||
| } | ||
|
|
||
| // 2. Run the function we want to test | ||
| props, err := gitlabProjectToProperties(mockProject) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error converting project to properties: %v", err) | ||
| } | ||
|
|
||
| // 3. Verify that the license was successfully populated and is not empty | ||
| licenseProp := props.GetProperty(RepoPropertyLicense) | ||
| if licenseProp == nil { | ||
| t.Fatal("expected license property to be populated, but got nil") | ||
| } | ||
|
|
||
| licenseVal, err := licenseProp.AsString() | ||
| if err != nil { | ||
| t.Fatalf("failed to read license property as string: %v", err) | ||
| } | ||
|
|
||
| if licenseVal != "Apache-2.0" { | ||
| t.Errorf("expected license 'Apache-2.0', got '%s'", licenseVal) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,8 +51,9 @@ | |
| ) (*gitlab.Project, error) { | ||
| projectURLPath, err := url.JoinPath("projects", url.PathEscape(upstreamID)) | ||
| if err != nil { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| return nil, fmt.Errorf("failed to join URL path for project using upstream ID: %w", err) | ||
| return nil, fmt.Errorf("failed to join URL path for project using upstream ID: %w", err) | ||
| } | ||
| projectURLPath = projectURLPath + "?license=true" | ||
|
|
||
| // NOTE: We're not using github.com/xanzy/go-gitlab to do the actual | ||
| // request here because of the way they form authentication for requests. | ||
|
|
||
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.
Why change this name to empty-string?