Skip to content

Commit

Permalink
some minor bug fixes/improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
darts committed Aug 4, 2024
1 parent 8fb6a64 commit b5aebb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ I saw a GraphQL tutorial while trying to understand some code in the Teams codeb

## Usage

1. Add Github PAT with _user_ permissions to environment variable `GITHUB_PAT` or start the application with a token argument.
Option A:

1. Add Github PAT with _user_ permissions to environment variable `GITHUB_PAT`.
2. Add Github username to the environment variable `GITHUB_USERNAME`.

Option B:

1. Pass the required Github PAT and username as the `t` and `u` arguments respectively.
2. Start the application. Arguments passed will override env variables.
3. (optional) If you're very weird you could run this as a system service I guess. Please let me know if you do, for science.

Expand Down
24 changes: 12 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
_ "embed"
"encoding/json"
"flag"
"fmt"
"log"
"math"
Expand Down Expand Up @@ -54,6 +55,7 @@ type authedTransport struct {

var graphqlClient *graphql.Client
var isWindows bool
var ghUserName string

//go:embed appsStatus.json
var jsonFile []byte
Expand Down Expand Up @@ -169,7 +171,7 @@ func parseAppsFromFile() *AppList {
func writeToGithubStatus(str string, emoji string, expiry time.Time) bool {
fmt.Printf("Writing to Github status: %s\n", str)
gqlReq := map[string]interface{}{
"input": ChangeUserStatusInput{ClientMutationId: "darts/status", Message: str, Emoji: emoji, ExpiresAt: expiry},
"input": ChangeUserStatusInput{ClientMutationId: fmt.Sprintf("%s/status", ghUserName), Message: str, Emoji: emoji, ExpiresAt: expiry},
}
err := graphqlClient.Mutate(context.Background(), &statusMutation, gqlReq)
if err != nil {
Expand Down Expand Up @@ -228,21 +230,19 @@ func resetOnClose() {
}

func initClient() {
authTokenEnv := os.Getenv("GITHUB_PAT")
authToken := os.Getenv("GITHUB_PAT")
ghUserName := os.Getenv("GITHUB_USERNAME")

var authTokenCmd = ""
if len(os.Args) > 1 {
authTokenCmd = os.Args[1]
}
flag.StringVar(&authToken, "t", authToken, "your github auth token")
flag.StringVar(&ghUserName, "u", ghUserName, "your github username")
flag.Parse()

if len(authTokenEnv) < 1 && len(authTokenCmd) < 1 {
log.Fatal("GITHUB_PAT env variable not set & no token passed to app.\nUsage: status <token>")
if len(authToken) < 1 {
log.Fatal("GITHUB_PAT env variable not set & no token passed to app!")
}

var authToken = authTokenEnv

if len(authTokenCmd) > 0 {
authToken = authTokenCmd
if len(ghUserName) < 1 {
log.Fatal("GITHUB_USERNAME env variable not set & no username passed to app!")
}

httpClient := http.Client{
Expand Down

0 comments on commit b5aebb3

Please sign in to comment.