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 basic ignore directive, allowing the user to tell anchor to ignore certain packages #38

Merged
merged 6 commits into from
Jul 27, 2024

Conversation

BradLewis
Copy link
Member

@BradLewis BradLewis commented Jul 18, 2024

First pass is just adding it for the apt packages, will do the docker images next and playing around with how it feels.

@BradLewis BradLewis requested a review from TheDen July 18, 2024 02:21
@BradLewis BradLewis self-assigned this Jul 18, 2024
@BradLewis BradLewis marked this pull request as ready for review July 22, 2024 00:48
README.md Outdated Show resolved Hide resolved
t.Errorf("Expected no error but got %v", err)
}
if image != "golang:1.22-bookworm" {
t.Errorf("Expected golang:1.22-bookworm but got %v", image)
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this be a %s, since image is a sting?

Suggested change
t.Errorf("Expected golang:1.22-bookworm but got %v", image)
t.Errorf("Expected golang:1.22-bookworm but got %s", image)

nodes := Parse(input)
image, err := processFromCommand(&nodes[0])
if err != nil {
t.Errorf("Expected no error but got %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
t.Errorf("Expected no error but got %v", err)
t.Errorf("Expected no error but got %w", err)

pkg/anchor/docker.go Show resolved Hide resolved
@@ -82,12 +94,55 @@ func processRunCommand(ctx context.Context, node *Node, architecture string, ima
return nil
}

func parseComment(entry Entry) ([]string, bool) {
Copy link
Member

Choose a reason for hiding this comment

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

Got GPT-4o to "refactor" this and what it claims (I don't know about readability compared to what you have though)—I'll leave it up to you:

Changes Made:

1.	Replaced strings.TrimLeft with strings.TrimSpace and strings.TrimPrefix for clarity and correctness.
2.	Used strings.Fields to split the command into parts more cleanly.
3.	Simplified the condition checks to enhance readability.
4.	Removed redundant TrimSpace calls in certain places where they were unnecessary.
func parseComment(entry Entry) ([]string, bool) {
	ignoredPackages := []string{}

	if entry.Type != EntryComment {
		return ignoredPackages, false
	}

	command := strings.TrimSpace(strings.TrimPrefix(entry.Value, "#"))
	parts := strings.Fields(command)

	if len(parts) < 2 || parts[0] != "anchor" {
		return ignoredPackages, false
	}

	keyValue := strings.SplitN(parts[1], "=", 2)

	if len(keyValue) < 2 {
		if strings.TrimSpace(keyValue[0]) == "ignore" {
			return ignoredPackages, true
		}
		return ignoredPackages, false
	}

	if keyValue[0] != "ignore" {
		return ignoredPackages, false
	}

	for _, pkg := range strings.Split(keyValue[1], ",") {
		ignoredPackages = append(ignoredPackages, strings.TrimSpace(pkg))
	}

	return ignoredPackages, false
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out this was just wrong lol but thanks chatgpt

@BradLewis BradLewis merged commit 2554f70 into main Jul 27, 2024
11 checks passed
@BradLewis BradLewis deleted the feat/add-ignore-directive branch July 27, 2024 01:25
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.

2 participants