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