Skip to content

Commit 6b8b876

Browse files
authored
Merge pull request #27 from PRODYNA/feature/26-mark-foreign-domains
feature/26 mark foreign domains
2 parents 62a024d + 70915ae commit 6b8b876

File tree

7 files changed

+38
-18
lines changed

7 files changed

+38
-18
lines changed

action.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ inputs:
2323
description: 'The verbosity level'
2424
required: false
2525
default: 1
26+
own-domains:
27+
description: 'Own domains to filter users by email domain'
28+
required: false
29+
default: ''
2630
runs:
2731
using: 'docker'
28-
image: 'docker://ghcr.io/prodyna/github-users:v1.8'
32+
image: 'docker://ghcr.io/prodyna/github-users:v1.9'
2933
env:
3034
ACTION: ${{ inputs.action }}
3135
ENTERPRISE: ${{ inputs.enterprise }}
3236
GITHUB_TOKEN: ${{ inputs.github-token }}
3337
TEMPLATE_FILE: ${{ inputs.template-file }}
3438
MARKDOWN_FILE: ${{ inputs.markdown-file }}
3539
VERBOSE: ${{ inputs.verbose }}
40+
OWN_DOMAINS: ${{ inputs.own-domains }}

config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const (
1515
keyTemplateFile = "TEMPLATE_FILE"
1616
keyVerbose = "VERBOSE"
1717
keyMarkdownFile = "MARKDOWN_FILE"
18+
keyOwnDomains = "OWN_DOMAINS"
1819
)
1920

2021
type Config struct {
@@ -23,6 +24,7 @@ type Config struct {
2324
GithubToken string
2425
TemplateFile string
2526
MarkdownFile string
27+
OwnDomains string
2628
}
2729

2830
func New() (*Config, error) {
@@ -32,6 +34,7 @@ func New() (*Config, error) {
3234
flag.StringVar(&c.GithubToken, keyGithubToken, lookupEnvOrString("GITHUB_TOKEN", ""), "The GitHub Token to use for authentication.")
3335
flag.StringVar(&c.TemplateFile, keyTemplateFile, lookupEnvOrString("TEMPLATE_FILE", "template/members.tpl"), "The template file to use for rendering the result.")
3436
flag.StringVar(&c.MarkdownFile, keyMarkdownFile, lookupEnvOrString("MARKDOWN_FILE", "USERS.md"), "The markdown file to write the result to.")
37+
flag.StringVar(&c.OwnDomains, keyOwnDomains, lookupEnvOrString("OWN_DOMAINS", ""), "The comma separated list of domains to consider as own domains.")
3538
verbose := flag.Int("verbose", lookupEnvOrInt(keyVerbose, 0), "Verbosity level, 0=info, 1=debug. Overrides the environment variable VERBOSE.")
3639

3740
level := slog.LevelInfo

main.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,6 @@ import (
77
"os"
88
)
99

10-
const (
11-
keyAction = "ACTION"
12-
keyOrganization = "ORGANIZATION"
13-
keyGithubToken = "GITHUB_TOKEN"
14-
keyTemplateFile = "TEMPLATE_FILE"
15-
)
16-
17-
type Config struct {
18-
Action string
19-
Enterprise string
20-
GithubToken string
21-
TemplateFile string
22-
}
23-
2410
func main() {
2511
c, err := config.New()
2612
if err != nil {
@@ -34,6 +20,7 @@ func main() {
3420
userlist.WithGithubToken(c.GithubToken),
3521
userlist.WithTemplateFile(c.TemplateFile),
3622
userlist.WithMarkdownFile(c.MarkdownFile),
23+
userlist.WithOwnDomains(c.OwnDomains),
3724
)
3825

3926
err = ulc.Validate()

template/members.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Last updated: {{ .Updated }}
44

55
| # | GitHub Login | GitHub name | E-Mail | Contributions |
66
| --- | --- | --- | --- | --- |
7-
{{ range .Users }} | {{ .Number }} | [{{ .Login }}](https://github.com/enterprises/{{ $.Enterprise.Slug }}/people/{{ .Login }}/sso) | {{ .Name }} | {{ .Email }} | {{if .Contributions}}:green_square:{{else}}:red_square:{{end}} [{{.Contributions }}](https://github.com/{{ .Login }}) |
7+
{{ range .Users }} | {{ .Number }} | [{{ .Login }}](https://github.com/enterprises/{{ $.Enterprise.Slug }}/people/{{ .Login }}/sso) | {{ .Name }} | {{ if .IsOwnDomain }}:green_square:{{else}}:red_square:{{end}} {{ .Email }} | {{if .Contributions}}:green_square:{{else}}:red_square:{{end}} [{{.Contributions }}](https://github.com/{{ .Login }}) |
88
{{ end }}
99

1010
{{ if .Users }}_{{ len .Users }} users_{{ else }}No users found.{{ end }}

userlist/constructor.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package userlist
22

3+
import "strings"
4+
35
func New(options ...func(*UserListConfig)) *UserListConfig {
46
config := &UserListConfig{
57
validated: false,
@@ -40,3 +42,9 @@ func WithMarkdownFile(markdownFile string) func(*UserListConfig) {
4042
config.markdownFile = markdownFile
4143
}
4244
}
45+
46+
func WithOwnDomains(ownDomains string) func(*UserListConfig) {
47+
return func(config *UserListConfig) {
48+
config.ownDomains = strings.Split(ownDomains, ",")
49+
}
50+
}

userlist/members.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/shurcooL/githubv4"
66
"golang.org/x/oauth2"
77
"log/slog"
8+
"strings"
89
"time"
910
)
1011

@@ -57,7 +58,7 @@ func (c *UserListConfig) loadMembers() error {
5758

5859
window := 25
5960
variables := map[string]interface{}{
60-
"slug": githubv4.String("prodyna"),
61+
"slug": githubv4.String(c.enterprise),
6162
"first": githubv4.Int(window),
6263
"after": (*githubv4.String)(nil),
6364
}
@@ -81,6 +82,7 @@ func (c *UserListConfig) loadMembers() error {
8182
Login: e.Node.User.Login,
8283
Name: e.Node.User.Name,
8384
Email: e.Node.SamlIdentity.NameId,
85+
IsOwnDomain: IsOwnDomain(e.Node.SamlIdentity.NameId, c.ownDomains),
8486
Contributions: e.Node.User.ContributionsCollection.ContributionCalendar.TotalContributions,
8587
}
8688
c.userList.upsertUser(u)
@@ -97,3 +99,15 @@ func (c *UserListConfig) loadMembers() error {
9799
c.loaded = true
98100
return nil
99101
}
102+
103+
func IsOwnDomain(email string, ownDomains []string) bool {
104+
if len(ownDomains) == 0 {
105+
return true
106+
}
107+
for _, domain := range ownDomains {
108+
if strings.HasSuffix(email, domain) {
109+
return true
110+
}
111+
}
112+
return false
113+
}

userlist/userlist.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type UserListConfig struct {
2525
validated bool
2626
loaded bool
2727
userList UserList
28+
ownDomains []string
2829
}
2930

3031
type UserList struct {
@@ -44,6 +45,7 @@ type User struct {
4445
Login string `json:"Login"`
4546
Name string `json:"Name"`
4647
Email string `json:"Email"`
48+
IsOwnDomain bool `json:"IsOwnDomain"`
4749
Contributions int `json:"Contributions"`
4850
Organizations *[]Organization
4951
}
@@ -80,7 +82,8 @@ func (c *UserListConfig) Validate() error {
8082
"enterprise", c.enterprise,
8183
"template", c.templateFile,
8284
"githubToken", "***",
83-
"markdownFile", c.markdownFile)
85+
"markdownFile", c.markdownFile,
86+
slog.Any("ownDomains", c.ownDomains))
8487
return nil
8588
}
8689

0 commit comments

Comments
 (0)