Skip to content
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

feat: add profile config support #77

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

liamstevens
Copy link

Implements #73

@liamstevens liamstevens force-pushed the feat/add-org-profile-config branch from 04bd800 to 406f0f3 Compare January 23, 2025 04:59
Copy link

codecov bot commented Jan 23, 2025

Codecov Report

Attention: Patch coverage is 95.40230% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/github/profile.go 95.06% 3 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
internal/config/config.go 0.00% <ø> (ø)
internal/github/token.go 88.46% <100.00%> (+0.14%) ⬆️
internal/vendor/vendor.go 100.00% <100.00%> (ø)
internal/github/profile.go 95.06% <95.06%> (ø)

@liamstevens liamstevens force-pushed the feat/add-org-profile-config branch 7 times, most recently from 6facfe2 to 51e02bd Compare January 24, 2025 02:59
@liamstevens
Copy link
Author

liamstevens commented Jan 24, 2025

@jamestelfer is there a way for me to get some better feedback from Codecov? I get 404s when I attempt to look at the report for the profile.go coverage.

@liamstevens liamstevens force-pushed the feat/add-org-profile-config branch from 51e02bd to d7a990e Compare January 24, 2025 03:35
@liamstevens liamstevens marked this pull request as ready for review January 24, 2025 03:59
@jamestelfer
Copy link
Collaborator

@coderabbitai review

docs/profile.yaml Outdated Show resolved Hide resolved
Copy link
Collaborator

@jamestelfer jamestelfer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is allowed because it's OSS (I'm saying).

Looks like a solid foundation, with some clearing up required on the access mechanism.

internal/github/profile.go Outdated Show resolved Hide resolved
internal/github/profile.go Outdated Show resolved Hide resolved
internal/github/profile_test.go Outdated Show resolved Hide resolved
internal/github/profile_test.go Outdated Show resolved Hide resolved
internal/github/profile_test.go Outdated Show resolved Hide resolved
internal/github/profile_test.go Outdated Show resolved Hide resolved
)

// Test that the profile URL is valid
func TestValidProfileURL(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer data tests

main.go Outdated
github.LoadProfile(ctx, gh, cfg.Server.OrgProfileURL)

// Start Goroutine to refresh the organization profile every 5 minutes
go func() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when this goroutine panics or finishes unexpectedly?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I believe newest changes should handle this - we want to log failures but not cascade the panic up to the main process.

@@ -59,6 +59,17 @@ func configureServerRoutes(ctx context.Context, cfg config.Config) (http.Handler
return nil, fmt.Errorf("vendor cache configuration failed: %w", err)
}

// Fetch the organization profile from the GitHub repository
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this to a function, possibly in the github package (better factored, easier tests).

The routine should update an instance of the profiles. The vendor needs to take a ConfigurationStore (or something) as a parameter so it can request the current configuration as needed.

Configuration access and updates need to be thread safe.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - makes sense!

I have updated with this pattern + threadsafe ways to access the config.

internal/vendor/vendor.go Outdated Show resolved Hide resolved
@liamstevens liamstevens force-pushed the feat/add-org-profile-config branch 5 times, most recently from bbf2516 to b7f4c4f Compare January 30, 2025 02:22
@liamstevens liamstevens force-pushed the feat/add-org-profile-config branch 2 times, most recently from 6eac054 to b7120ff Compare January 30, 2025 02:38
@jamestelfer
Copy link
Collaborator

@liamstevens did you work out the coverage issue?

Copy link

@therealvio therealvio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor items that we can probably do at the end of the reviews.

internal/github/profile.go Outdated Show resolved Hide resolved
}

func (config *ProfileConfig) HasRepository(profileName string, repo string) bool {
profile, ok := config.HasProfile(profileName)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loves me some comma ok idiom

internal/github/profile_test.go Outdated Show resolved Hide resolved
var invalidProfile string

// Test that the
func TestURLDecomposition(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case anyone thinks about it: I was originally going to ask if a table-driven test would be worthwhile, but given it's 2 different cases with little variation, we can probably leave this as-is since there wouldn't be much value setting up that framework.

@liamstevens
Copy link
Author

@liamstevens did you work out the coverage issue?

Yep, I didn't do anything to fix it, but the codecov links stopped 404ing for me.

@liamstevens liamstevens requested review from a team and therealvio January 30, 2025 06:25
@liamstevens liamstevens force-pushed the feat/add-org-profile-config branch from bb21766 to 031dc96 Compare January 31, 2025 05:20
@liamstevens liamstevens force-pushed the feat/add-org-profile-config branch from 031dc96 to c463276 Compare January 31, 2025 05:21

func LoadProfile(ctx context.Context, gh Client, orgProfileURL string) (ProfileConfig, error) {
// get the profile
profile, err := GetProfile(ctx, gh, orgProfileURL)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to beacon out to audit logs when this is updated.

This should be done through the response from GitHub - look at the hashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants