Skip to content

Commit

Permalink
chore: split github-dump prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Aug 1, 2023
1 parent 2445416 commit 30f45aa
Show file tree
Hide file tree
Showing 9 changed files with 539 additions and 292 deletions.
16 changes: 12 additions & 4 deletions tests/sandbox/github-dump/api.http
Expand Up @@ -4,30 +4,38 @@
GET https://api.github.com/user/repos?per_page=1&page=1
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
X-GitHub-Api-Version: {{version}}

###

# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repositories-for-a-user
GET https://api.github.com/users/{{user}}/repos?per_page=1&page=1
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
X-GitHub-Api-Version: {{version}}

###

# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-organization-repositories
GET https://api.github.com/orgs/{{org}}/repos?per_page=1&page=1
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
X-GitHub-Api-Version: {{version}}

###

# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#get-a-repository
GET https://api.github.com/repos/{{user}}/{{repo}}
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: {{version}}

###

# https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#get-a-repository-readme
GET https://api.github.com/repos/{{user}}/{{repo}}/readme
Accept: application/vnd.github+json
Authorization: Bearer {{token}}
X-GitHub-Api-Version: 2022-11-28
X-GitHub-Api-Version: {{version}}

###
128 changes: 128 additions & 0 deletions tests/sandbox/github-dump/config.go
@@ -0,0 +1,128 @@
package main

import (
"os"
"regexp"

"github.com/BurntSushi/toml"
"go.octolab.org/safe"
"go.octolab.org/unsafe"
)

func Load(name string) (Config, error) {
cnf := defaults()

f, err := os.Open(name)
if err != nil {
return cnf, err
}
defer safe.Close(f, unsafe.Ignore)

if _, err := toml.NewDecoder(f).Decode(&cnf); err != nil {
return cnf, err
}
return cnf, cnf.Index()
}

type Config struct {
GitHub struct {
Affiliation []string `toml:"affiliation"`
Tags []string `toml:"tags"`
Readme string `toml:"readme"`
Limit int `toml:"limit"`

Canonical []struct {
Name string `toml:"name"`
Real string `toml:"real"`
} `toml:"canonical"`
canonicals map[string]string

Aliases []struct {
SSH string `toml:"ssh"`
Aliases []string `toml:"aliases"`
} `toml:"aliases"`
aliases map[string][]string

Include struct {
List []string `toml:"list"`
list map[string]struct{}
} `toml:"include"`

Exclude struct {
List []string `toml:"list"`
list map[string]struct{}

Patterns []string `toml:"patterns"`
patterns []*regexp.Regexp
} `toml:"exclude"`
} `toml:"github"`
}

func (cnf *Config) Index() error {
cnf.GitHub.canonicals = make(map[string]string)
for _, canonical := range cnf.GitHub.Canonical {
cnf.GitHub.canonicals[canonical.Real] = canonical.Name
}

cnf.GitHub.aliases = make(map[string][]string)
for _, alias := range cnf.GitHub.Aliases {
cnf.GitHub.aliases[alias.SSH] = alias.Aliases
}

cnf.GitHub.Include.list = make(map[string]struct{})
for _, include := range cnf.GitHub.Include.List {
cnf.GitHub.Include.list[include] = struct{}{}
}

cnf.GitHub.Exclude.list = make(map[string]struct{})
for _, exclude := range cnf.GitHub.Exclude.List {
cnf.GitHub.Exclude.list[exclude] = struct{}{}
}

size := len(cnf.GitHub.Exclude.Patterns)
cnf.GitHub.Exclude.patterns = make([]*regexp.Regexp, 0, size)
for _, pattern := range cnf.GitHub.Exclude.Patterns {
r, err := regexp.Compile(pattern)
if err != nil {
return err
}
cnf.GitHub.Exclude.patterns = append(cnf.GitHub.Exclude.patterns, r)
}
return nil
}

func defaults() Config {
var cnf Config
cnf.GitHub.Affiliation = []string{"owner"}
cnf.GitHub.Tags = []string{"github", "repository"}
cnf.GitHub.Readme = "README.md"
cnf.GitHub.Limit = 100

// TODO:feature future implementation
// some names from differed orgs are matched
collision := "{{ .GetFullName | title }}"
// sometimes readme are missed
readme := struct {
name string
alt struct {
tags []string
content string
}
}{
name: "README.md",
alt: struct {
tags []string
content string
}{
tags: []string{"debt", "todo"},
content: `
# {{ .GetName | emoji }}
{{ .GetDescription }}
`,
},
}
_, _ = collision, readme

return cnf
}
136 changes: 87 additions & 49 deletions tests/sandbox/github-dump/config.toml
@@ -1,136 +1,174 @@
[repository]
[github]
affiliation = ['owner', 'organization_member']
tags = ['github', 'repository']

[[repository.aliases]]
readme = "README.md"
limit = 100

collision = "{{ .GetName }} at {{ .GetLogin .GetOwner }}"
[github.alt]
tags = ['debt', 'todo']
draft = """
# {{ .GetName | emoji }}
{{ .GetDescription }}
"""

[github.include]
list = [
'kamilsk/godownloader',
'kamilsk/go-tools',
'kamilsk/golangci-lint',
'under-the-hood/persona',
]

[github.exclude]
list = [
'kamilsk/algobox',
'kamilsk/CilexServiceProviders',
'kamilsk/Common',
'kamilsk/ideas',
'kamilsk/kamilsk',
'kamilsk/Kilex',
'kamilsk/notes',
'kamilsk/pmc',
'kamilsk/SilexServiceProviders',
'kamilsk/workshops',
]
patterns = [
'\w*\.\w+',
'^under-the-hood/',
'/site$',
]

[[github.canonical]]
name = 'tact'
real = 'tact-app'

[[github.canonical]]
name = 'research'
real = 'under-the-hood'

[[github.canonical]]
name = 'sparkle'
real = 'withsparkle'

[[github.aliases]]
ssh = 'git@github.com:kamilsk/go-tools.git'
aliases = ['goimports']

[[github.aliases]]
ssh = 'git@github.com:octolab/breakit.git'
aliases = ['go.octolab.org/toolset/breakit']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octolab/cli.git'
aliases = ['go.octolab.org/toolkit/cli']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octolab/config.git'
aliases = ['go.octolab.org/toolkit/config']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octolab/maintainer.git'
aliases = ['go.octolab.org/toolset/maintainer']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octolab/parallel.git'
aliases = ['go.octolab.org/toolset/parallel']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octolab/pkg.git'
aliases = ['go.octolab.org']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octolab/propaganda.git'
aliases = ['go.octolab.org/propaganda']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octolab/protocol.git'
aliases = ['go.octolab.org/toolkit/protocol']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octolab/testit.git'
aliases = ['go.octolab.org/toolset/testit']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octolab/try.git'
aliases = ['go.octolab.org/toolset/try']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octomation/go-module.git'
aliases = ['go.octolab.org/template/module']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octomation/go-service.git'
aliases = ['go.octolab.org/template/service']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octomation/go-tool.git'
aliases = ['go.octolab.org/template/tool']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octomation/tablo.git'
aliases = ['go.octolab.org/ecosystem/tablo']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octopot/forma.git'
aliases = ['go.octolab.org/ecosystem/forma']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octopot/guard.git'
aliases = ['go.octolab.org/ecosystem/guard']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:octopot/passport.git'
aliases = ['go.octolab.org/ecosystem/passport']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:tact-app/airseat.git'
aliases = ['go.octolab.org/toolset/airseat']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:tact-app/beads.git'
aliases = ['go.octolab.org/ecosystem/beads']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:tact-app/click.git'
aliases = ['go.octolab.org/ecosystem/click']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:tact-app/github.git'
aliases = ['go.octolab.org/tact/inbox/github']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:tact-app/inbox.git'
aliases = ['go.octolab.org/template/inbox']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:tact-app/loop.git'
aliases = ['go.octolab.org/toolset/loop']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:tact-app/optflow.git'
aliases = ['go.octolab.org/toolset/optflow']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:tact-app/secret.git'
aliases = ['go.octolab.org/toolset/secret']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:tact-app/service.git'
aliases = ['go.octolab.org/ecosystem/tact']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:tact-app/trello.git'
aliases = ['go.octolab.org/tact/inbox/trello']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:withsparkle/fiddle.git'
aliases = ['go.octolab.org/toolset/fiddle']

[[repository.aliases]]
[[github.aliases]]
ssh = 'git@github.com:withsparkle/service.git'
aliases = ['go.octolab.org/ecosystem/sparkle']

[repository.exclude]
list = [
'kamilsk/algobox',
'kamilsk/CilexServiceProviders',
'kamilsk/Common',
'kamilsk/ideas',
'kamilsk/kamilsk',
'kamilsk/Kilex',
'kamilsk/notes',
'kamilsk/pmc',
'kamilsk/SilexServiceProviders',
'kamilsk/workshops',
]
patterns = [
'\w*\.\w+',
'^under-the-hood/',
'/site$',
]

0 comments on commit 30f45aa

Please sign in to comment.