Debian Codegraph @

docs/content/en/methods/page/CodeOwners.md

raw
1 ---
2 title: CodeOwners
3 description: Returns a slice of code owners for the given page, derived from the CODEOWNERS file in the root of the project directory.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: '[]string'
9 signatures: [PAGE.CodeOwners]
10 ---
11
12 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:
13
14 - [GitHub CODEOWNERS documentation][]
15 - [GitLab CODEOWNERS documentation][]
16
17 Use the `CodeOwners` method on a `Page` object to determine the code owners for the given page.
18
19 To use the `CodeOwners` method you must enable access to your local Git repository:
20
21 {{< code-toggle file=hugo >}}
22 enableGitInfo = true
23 {{< /code-toggle >}}
24
25 Consider this project structure:
26
27 ```tree
28 my-project/
29 ├── content/
30 │ ├── books/
31 │ │ └── les-miserables.md
32 │ └── films/
33 │ └── the-hunchback-of-notre-dame.md
34 └── CODEOWNERS
35 ```
36
37 And this CODEOWNERS file:
38
39 ```text
40 * @jdoe
41 /content/books/ @tjones
42 /content/films/ @mrichards @rsmith
43 ```
44
45 The table below shows the slice of code owners returned for each file:
46
47 Path|Code owners
48 :--|:--
49 `books/les-miserables.md`|`[@tjones]`
50 `films/the-hunchback-of-notre-dame.md`|`[@mrichards @rsmith]`
51
52 Render the code owners for each content page:
53
54 ```go-html-template
55 {{ range .CodeOwners }}
56 {{ . }}
57 {{ end }}
58 ```
59
60 Combine this method with [`resources.GetRemote`][] to retrieve names and avatars from your Git provider by querying their API.
61
62 [GitHub CODEOWNERS documentation]: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
63 [GitLab CODEOWNERS documentation]: https://docs.gitlab.com/ee/user/project/code_owners.html
64 [`resources.GetRemote`]: /functions/resources/getremote/