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

Relocate comments to rego.Function.Description in preparation for auto-generating documentation. #5354

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

evankanderson
Copy link
Member

Summary

This moves all the large, helpful Golang comments into the Function.Description field. The next step will be to convert all the existing func(*interfaces.Result) func(*rego.Rego) functions to entries in a list, like so:

type vfsFunc(billy.Filesystem) rego.BuiltinDyn

type FunctionEntry struct {
  // The rego function definition (metadata)
  decl *rego.Function

  // Only one of the following should be set:

  // A bare function implementation which does not need a vfs
  bareImpl rego.BuiltinDyn
  // A function implementation that should receive the current vfs
  vfsImpl  vfsFunc
  // A function implementation that sohuld receive the pre-change vfs
  baseImpl vfsFunc
}

In that PR, we can then convert the existing initialization to:

var MinderRegoLib = []FunctionEntry{
  FileExists,
  ...
}

var FileExists = FunctionEntry{
  decl: &rego.Function{
    ...
  },
  vfsImpl: fsExists,
}
...

Which allows us to iterate over MinderRegoLib, extract the decl.Description (and decl.Name) to generate a markdown file of all the custom functions in the Minder Rego runtime. We can then include these in the reference section of the documentation.

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Existing unit tests.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@evankanderson evankanderson requested a review from a team as a code owner January 26, 2025 05:50
@coveralls
Copy link

coveralls commented Jan 26, 2025

Coverage Status

coverage: 56.836% (+0.1%) from 56.687%
when pulling 6c961a8 on evankanderson:doc-functions
into 0f726c7 on mindersec:main.

Copy link
Contributor

@JAORMX JAORMX left a comment

Choose a reason for hiding this comment

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

Lovely!

@eleftherias eleftherias merged commit 33c7061 into mindersec:main Jan 27, 2025
26 checks passed
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