-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 87a48cb
Showing
16 changed files
with
6,859 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
api: | ||
name: api | ||
color: 6f42c1 | ||
description: Issues related to the GitHub API | ||
bug: | ||
name: bug | ||
color: d73a4a | ||
description: Something isn't working as expected | ||
enhancement: | ||
name: enhancement | ||
color: 0dd8ac | ||
description: New feature or improvement request | ||
documentation: | ||
name: documentation | ||
color: 007bc7 | ||
description: Issues related to documentation | ||
help-wanted: | ||
name: help-wanted | ||
color: 7057ff | ||
description: Contribution opportunities available | ||
question: | ||
name: question | ||
color: ffb000 | ||
description: Questions or need for further clarification | ||
invalid: | ||
name: invalid | ||
color: e4e669 | ||
description: Issue is no longer valid or applicable | ||
duplicate: | ||
name: duplicate | ||
color: cfd3d7 | ||
description: Issue already reported or duplicated | ||
wontfix: | ||
name: wontfix | ||
color: a2eeef | ||
description: Issue won't be fixed or addressed | ||
feature-request: | ||
name: feature-request | ||
color: 61dafb | ||
description: Request for a new feature or enhancement | ||
critical: | ||
name: critical | ||
color: e00808 | ||
description: Critical issue that requires immediate attention | ||
high-priority: | ||
name: high-priority | ||
color: ff7b72 | ||
description: Issue with high priority | ||
low-priority: | ||
name: low-priority | ||
color: 8c8c8c | ||
description: Issue with low priority | ||
in-progress: | ||
name: in-progress | ||
color: 2a8b9d | ||
description: Issue currently being worked on | ||
resolved: | ||
name: resolved | ||
color: 28a745 | ||
description: Issue has been resolved | ||
feedback: | ||
name: feedback | ||
color: d4c5f9 | ||
description: Feedback or suggestions for improvement | ||
testing: | ||
name: testing | ||
color: 36bcef | ||
description: Issues related to testing or test cases | ||
hacktoberfest: | ||
name: hacktoberfest | ||
color: ff6b00 | ||
description: Issues related to the Hacktoberfest event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Upload labels | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
|
||
permissions: write-all | ||
|
||
jobs: | ||
upload-labels: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
- run: go install github.com/shanduur/labeler/cmd/labeler@main | ||
- run: labeler upload --owner shanduur --repo labeler ./.github/labels.yaml | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.LABELER_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package download | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"path" | ||
"strings" | ||
|
||
"github.com/google/go-github/v53/github" | ||
"github.com/shanduur/labeler/labels" | ||
"github.com/urfave/cli/v3" | ||
"golang.org/x/exp/slog" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
var ( | ||
output string | ||
|
||
flagOutput = &cli.StringFlag{ | ||
Name: "output", | ||
Aliases: []string{"o"}, | ||
Destination: &output, | ||
} | ||
) | ||
|
||
func New() *cli.Command { | ||
return &cli.Command{ | ||
Name: "download", | ||
Aliases: []string{"d", "dl"}, | ||
Flags: []cli.Flag{ | ||
flagOutput, | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
if ctx.Args().Len() == 0 { | ||
return errors.New("nothing to do") | ||
} | ||
|
||
client := github.NewClient(nil) | ||
|
||
for i := 0; i < ctx.NArg(); i++ { | ||
ghPath := ctx.Args().Get(i) | ||
owner, repo := getOwnerRepo(ghPath) | ||
|
||
l, err := listAll(ctx.Context, client, owner, repo) | ||
if err != nil { | ||
return fmt.Errorf("unable to list all: %w", err) | ||
} | ||
|
||
b, err := toYAML(l) | ||
if err != nil { | ||
return fmt.Errorf("converision failed: %w", err) | ||
} | ||
|
||
outputPath := ghPath | ||
if output != "" { | ||
outputPath = path.Join(output, ghPath) | ||
} | ||
|
||
err = save(outputPath, b) | ||
if err != nil { | ||
return fmt.Errorf("saving failed: %w", err) | ||
} | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func getOwnerRepo(arg string) (string, string) { | ||
args := strings.SplitN(arg, "/", 2) | ||
if len(args) == 2 { | ||
return args[0], args[1] | ||
} | ||
return "", "" | ||
} | ||
|
||
func listAll(ctx context.Context, client *github.Client, owner, repo string) ([]*github.Label, error) { | ||
slog.Debug("listing", "owner", owner, "repo", repo) | ||
var ( | ||
page = 0 | ||
allLabels []*github.Label | ||
) | ||
|
||
if client == nil { | ||
return nil, errors.New("client is nil") | ||
} | ||
|
||
for { | ||
labels, res, err := client.Issues.ListLabels(ctx, owner, repo, &github.ListOptions{ | ||
Page: page, | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to list labels: %w", err) | ||
} | ||
|
||
allLabels = append(allLabels, labels...) | ||
|
||
if res.NextPage == 0 { | ||
break | ||
} | ||
page = res.NextPage | ||
} | ||
|
||
slog.Debug("listing done", "labels_count", len(allLabels)) | ||
|
||
return allLabels, nil | ||
} | ||
|
||
func toYAML(ghl []*github.Label) ([]byte, error) { | ||
slog.Debug("transforming to YAML") | ||
|
||
lbl := make(labels.Labels) | ||
|
||
for _, l := range ghl { | ||
name := l.GetName() | ||
if _, ok := lbl[name]; ok { | ||
slog.Warn("duplicate found", "name", name) | ||
continue | ||
} | ||
|
||
slog.Debug("new label", "name", name) | ||
|
||
lbl[name] = labels.Label{ | ||
Name: l.GetName(), | ||
Color: l.GetColor(), | ||
Description: l.Description, | ||
} | ||
} | ||
|
||
slog.Debug("transforming to YAML complete") | ||
|
||
out, err := yaml.Marshal(lbl) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to marshall YAML: %w", err) | ||
} | ||
|
||
return out, nil | ||
} | ||
|
||
func save(location string, data []byte) error { | ||
err := os.MkdirAll(location, 0o777) | ||
if err != nil { | ||
return fmt.Errorf("unable to create directory: %w", err) | ||
} | ||
|
||
output := path.Join(location, "labels.yaml") | ||
|
||
slog.Debug("saving to file", "location", output) | ||
|
||
err = os.WriteFile(output, data, 0o644) | ||
if err != nil { | ||
return fmt.Errorf("unable to save result: %w", err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.