Skip to content

Commit

Permalink
2021 updates (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonEgger authored Oct 8, 2021
1 parent 9f0da0c commit 1df77db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ and `hacktoberfest-accepted` labels in your repos.
1. Download the latest release from [the releases page](https://github.com/do-community/hacktoberfest-repo-topic-apply/releases/).
2. Either move the binary to `/usr/local/bin` or run it locally.

## Create a GitHub Token
## Create an Access Token

You will need a GitHub token to perform these actions on your repositories. Follow the instructions for [creating a personal access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) and be sure to give it `repo` access.
If you are using Gitlab instead, follow these instructions for [creating a personal access token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) instead.
You will need an access token to perform these actions on your repositories. Follow the instructions for [creating a personal access token on GitHub](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) and be sure to give it `repo` access.
If you are using GitLab instead, follow these instructions for [creating a personal access token on GitLab](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) instead.


## Usage
Expand All @@ -24,15 +24,15 @@ hfest-repo -t <TOKEN>
```
If you don't specify your GitHub token, the tool will look for an environment variable named `ACCESS_TOKEN`.

To use Gitlab instead of Github
To use GitLab instead of GitHub

```sh
hfest-repo -vcs Gitlab -t <TOKEN>
```

if you don't specify your version control system, Github or Gitlab, it will default to Github.

### The "Default Hacktoberfest run this on my stuff" command
### The "Default Hacktoberfest run this on my stuff in GitHub" command

```sh
hfest-repo -t <TOKEN> -u <USER> --labels
Expand Down Expand Up @@ -86,10 +86,11 @@ usage: hfest-repo [<flags>]
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
-V, --vcs="Github" GitHub or GitLab, defaults to GitHub
-t, --access-token=ACCESS-TOKEN
GitHub or Gitlab API Token - if unset, attempts to use this tool's stored token of its current default context. env var: ACCESS_TOKEN
-u, --user=GH-USER Github or Gitlab user to fetch repos of
-o, --org=GH-ORG Github org or Gitlab group to fetch repos of
GitHub or GitLab API Token - if unset, attempts to use this tool's stored token of its current default context. env var: ACCESS_TOKEN
-u, --user=USER Github or Gitlab user to fetch repos of
-o, --org=ORG Github org or Gitlab group to fetch repos of
-p, --topic="hacktoberfest" topic to add to repos
-r, --remove Remove hacktoberfest topic from all repos
-l, --labels Add spam, invalid, and hacktoberfest-accepted labels to repo
Expand Down
26 changes: 13 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 Kamal Nasser All rights reserved.
Copyright 2020 Mason Egger All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down Expand Up @@ -28,10 +28,10 @@ import (
)

var (
vcs = kingpin.Flag("vcs", "Github or Gitlab, defaults to Github").Short('V').Default("Github").String()
accessToken = kingpin.Flag("access-token", "GitHub or Gitlab API Token - if unset, attempts to use this tool's stored token of its current default context. env var: GITHUB_ACCESS_TOKEN").Short('t').Envar("GITHUB_ACCESS_TOKEN").String()
user = kingpin.Flag("user", "Github or Gitlab user to fetch repos of").Short('u').String()
org = kingpin.Flag("org", "Github org or Gitlab group to fetch repos of").Short('o').String()
vcs = kingpin.Flag("vcs", "Github or Gitlab, defaults to Github").Short('V').Default("Github").String()
accessToken = kingpin.Flag("access-token", "GitHub or Gitlab API Token - if unset, attempts to use this tool's stored token of its current default context. env var: ACCESS_TOKEN").Short('t').Envar("ACCESS_TOKEN").String()
user = kingpin.Flag("user", "Github or Gitlab user to fetch repos of").Short('u').String()
org = kingpin.Flag("org", "Github org or Gitlab group to fetch repos of").Short('o').String()
topic = kingpin.Flag("topic", "topic to add to repos").Short('p').Default("hacktoberfest").String()
remove = kingpin.Flag("remove", "Remove hacktoberfest topic from all repos").Short('r').Default("false").Bool()
labels = kingpin.Flag("labels", "Add spam, invalid, and hacktoberfest-accepted labels to repo").Short('l').Default("false").Bool()
Expand All @@ -46,18 +46,18 @@ func main() {
log.SetHandler(cli.Default)

if *accessToken == "" {
log.Info("no access token provided, attempting to look up githubs's access token in env vars")
token := os.Getenv("GITHUB_ACCESS_TOKEN")
log.Info("no access token provided, attempting to look up access token in env vars")
token := os.Getenv("ACCESS_TOKEN")
if token == "" {
log.Fatalf("couldn't look up token")
log.Fatalf("couldn't look up token in ACCESS_TOKEN")
}

*accessToken = token
log.Info("using github's access token found in env vars")
log.Info("using access token found in env vars")
}

if *org == "" && *user == "" {
log.Fatalf("Neither user or githubOrg was set.")
log.Fatalf("Neither user or org was set.")
}

ctx := context.Background()
Expand Down Expand Up @@ -109,7 +109,7 @@ func main() {
var allReposNoForks []*gitlab.Project
for _, repo := range allRepos {
if repo.ForkedFromProject == nil {
allReposNoForks = append(allReposNoForks, repo)
allReposNoForks = append(allReposNoForks, repo)
}
}
allRepos = allReposNoForks
Expand Down Expand Up @@ -185,7 +185,7 @@ func main() {
break
}
labelColors := map[string]string{
"hacktoberfest-accepted": "#9c4668",
"hacktoberfest-accepted": "#f54501",
"invalid": "#ca0b00",
"spam": "#b33a3a",
}
Expand All @@ -203,7 +203,7 @@ func main() {
loggerWithFields.WithField("label", label).Info("adding labels")
}
}

}
} else {
loggerWithFields.WithField("topic", *topic).Infof("[dryrun] %s topic", operation)
Expand Down

0 comments on commit 1df77db

Please sign in to comment.