hugo/docs/content/en/methods/page/CodeOwners.md
2023-12-04 15:24:01 +01:00

1.9 KiB

title description categories keywords action
CodeOwners Returns of slice of code owners for the given page, derived from the CODEOWNERS file in the root of the project directory.
related returnType signatures
methods/page/GitInfo
[]string
PAGE.CodeOwners

GitHub and GitLab support CODEOWNERS files. This file specifies the users responsible for developing and maintaining software and documentation. This definition can apply to the entire repository, specific directories, or to individual files. To learn more:

Use the CodeOwners method on a Page object to determine the code owners for the given page.

To use the CodeOwners method you must enable access to your local Git repository:

{{< code-toggle file=hugo >}} enableGitInfo = true {{< /code-toggle >}}

Consider this project structure:

hugo-testing/
├── content/
│   ├── books/
│   │   └── les-miserables.md
│   └── films/
│       └── the-hunchback-of-notre-dame.md
└── CODEOWNERS

And this CODEOWNERS file:

* @jdoe
/content/books/ @tjones
/content/films/ @mrichards @rsmith

The table below shows the slice of code owners returned for each file:

Path Code owners
books/les-miserables.md [@tjones]
films/the-hunchback-of-notre-dame.md [@mrichards @rsmith]

Render the code owners for each content page:

{{ range .CodeOwners }}
  {{ . }}
{{ end }}

Combine this method with resources.GetRemote to retrieve names and avatars from your Git provider by querying their API.