Skip to content

Commit d06a5e6

Browse files
committed
initial commit
0 parents  commit d06a5e6

13 files changed

Lines changed: 444 additions & 0 deletions

File tree

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
6+
end_of_line = lf
7+
8+
insert_final_newline = true
9+
10+
trim_trailing_whitespace = true
11+
12+
indent_style = space
13+
14+
[*.md]
15+
trim_trailing_whitespace = false
16+
17+
[*.yml]
18+
indent_size = 2
19+
20+
[*.go]
21+
indent_size = 4

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PORT=XXXX
2+
PERSONAL_ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
3+
ORG_NAME=Portchain
4+
USER_NAME=utkuufuk
5+
SUBSCRIBED_REPOS=entrello,github-service

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: github-service
2+
on:
3+
push:
4+
jobs:
5+
ci:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@master
10+
11+
- name: Setup Go
12+
uses: actions/setup-go@v1
13+
with:
14+
go-version: 1.18
15+
16+
- name: Check gofmt
17+
run: test -z "$(gofmt -s -d .)"
18+
19+
- name: Run go vet
20+
run: go vet ./...
21+
22+
- name: Check go.mod
23+
run: go mod tidy && git diff --no-patch --exit-code
24+
25+
- name: Build
26+
run: go build ./cmd/github-service
27+
28+
- name: Run tests
29+
run: go test ./...

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: bin/github-service

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Deploying to Heroku
2+
The Heroku app is updated whenever a new commit is pushed to the `master` branch.

cmd/github-service/main.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"flag"
7+
"fmt"
8+
"log"
9+
"net/http"
10+
"os"
11+
12+
"github.com/utkuufuk/entrello/pkg/trello"
13+
"github.com/utkuufuk/github-service/internal/config"
14+
"github.com/utkuufuk/github-service/internal/github"
15+
)
16+
17+
func main() {
18+
terminalMode := flag.Bool("t", false, "Run in terminal mode")
19+
flag.Parse()
20+
21+
client := github.GetClient()
22+
funRepo := map[string]func(ctx context.Context) ([]trello.Card, error){
23+
"": client.FetchAssignedIssues,
24+
"prlo": client.FetchOtherPullRequests(),
25+
"prlmy": client.FetchMyPullRequests,
26+
"prlme": client.FetchOtherPullRequestsAssignedToMe,
27+
}
28+
29+
if !*terminalMode {
30+
http.HandleFunc("/entrello", handleGetRequest(funRepo[""]))
31+
http.HandleFunc("/entrello/prlo", handleGetRequest(funRepo["prlo"]))
32+
http.HandleFunc("/entrello/prlme", handleGetRequest(funRepo["prlme"]))
33+
http.HandleFunc("/entrello/prlmy", handleGetRequest(funRepo["prlmy"]))
34+
http.ListenAndServe(fmt.Sprintf(":%d", config.Port), nil)
35+
return
36+
}
37+
38+
if len(os.Args) == 2 {
39+
displayCards(funRepo[""])
40+
return
41+
}
42+
43+
switch os.Args[2] {
44+
case "prlo":
45+
displayCards(funRepo["prlo"])
46+
case "prlmy":
47+
displayCards(funRepo["prlmy"])
48+
case "prlme":
49+
displayCards(funRepo["prlme"])
50+
default:
51+
log.Fatalf("Uncrecognized command: %s", os.Args[2])
52+
}
53+
}
54+
55+
func handleGetRequest(
56+
fetchCards func(ctx context.Context) ([]trello.Card, error),
57+
) func(w http.ResponseWriter, r *http.Request) {
58+
return func(w http.ResponseWriter, r *http.Request) {
59+
if r.Method != http.MethodGet {
60+
w.WriteHeader(http.StatusMethodNotAllowed)
61+
return
62+
}
63+
64+
cards, err := fetchCards(r.Context())
65+
if err != nil {
66+
w.WriteHeader(http.StatusInternalServerError)
67+
fmt.Fprintf(w, "could not fetch github cards for entrello: %v", err)
68+
return
69+
}
70+
71+
w.Header().Set("Content-Type", "application/json")
72+
json.NewEncoder(w).Encode(cards)
73+
}
74+
}
75+
76+
func displayCards(query func(ctx context.Context) ([]trello.Card, error)) {
77+
cards, err := query(context.Background())
78+
if err != nil {
79+
log.Fatalf(err.Error())
80+
}
81+
82+
for _, c := range cards {
83+
fmt.Printf("%s - %s\n", c.Name, c.Desc)
84+
}
85+
}

go.mod

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module github.com/utkuufuk/github-service
2+
3+
// +heroku goVersion go1.18
4+
go 1.18
5+
6+
require (
7+
github.com/google/go-github/v39 v39.1.0
8+
github.com/joho/godotenv v1.4.0
9+
github.com/utkuufuk/entrello v1.1.2
10+
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
11+
)
12+
13+
require (
14+
github.com/adlio/trello v1.8.0 // indirect
15+
github.com/golang/protobuf v1.3.2 // indirect
16+
github.com/google/go-querystring v1.1.0 // indirect
17+
github.com/pkg/errors v0.9.1 // indirect
18+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
19+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
20+
google.golang.org/appengine v1.6.7 // indirect
21+
gopkg.in/yaml.v2 v2.4.0 // indirect
22+
)

go.sum

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
github.com/adlio/trello v1.8.0 h1:VU/1zwzuRzATsFC8WiK4f8R0HHQPWpf2H658KEchsmA=
2+
github.com/adlio/trello v1.8.0/go.mod h1:l2068AhUuUuQ9Vsb95ECMueHThYyAj4e85lWPmr2/LE=
3+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
4+
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM=
5+
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
6+
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
7+
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
8+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
9+
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
10+
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
11+
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
12+
github.com/google/go-github/v39 v39.1.0 h1:1vf4gM0D1e+Df2HMxaYC3+o9+Huj3ywGTtWc3VVYaDA=
13+
github.com/google/go-github/v39 v39.1.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE=
14+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
15+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
16+
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
17+
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
18+
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
19+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
20+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
21+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
22+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
23+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
24+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
25+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
26+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
27+
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
28+
github.com/utkuufuk/entrello v1.1.2 h1:R+SeWKlfH/hc05DhBS3ina3v9oJEo3iWoh2dUjuEedA=
29+
github.com/utkuufuk/entrello v1.1.2/go.mod h1:zzBRIqCPdDaWZDFehYn2yAQf48RvNaO0HQz5Z8nbc4A=
30+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
31+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
32+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
33+
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
34+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
35+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
36+
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
37+
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
38+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
39+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
40+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
41+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
42+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
43+
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
44+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
45+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
46+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
47+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
48+
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
49+
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
50+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
51+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
52+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
53+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
54+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

internal/config/config.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package config
2+
3+
import (
4+
"os"
5+
"strconv"
6+
"strings"
7+
8+
"github.com/joho/godotenv"
9+
"github.com/utkuufuk/github-service/internal/logger"
10+
)
11+
12+
var (
13+
Port int
14+
PersonalAccessToken string
15+
OrgName string
16+
UserName string
17+
SubscribedRepos []string
18+
)
19+
20+
func init() {
21+
var err error
22+
godotenv.Load()
23+
24+
port := os.Getenv("PORT")
25+
Port, err = strconv.Atoi(port)
26+
if err != nil {
27+
logger.Error("PORT not set")
28+
os.Exit(1)
29+
}
30+
31+
PersonalAccessToken = os.Getenv("PERSONAL_ACCESS_TOKEN")
32+
if PersonalAccessToken == "" {
33+
logger.Error("PERSONAL_ACCESS_TOKEN not set")
34+
os.Exit(1)
35+
}
36+
37+
OrgName = os.Getenv("ORG_NAME")
38+
if OrgName == "" {
39+
logger.Error("ORG_NAME not set")
40+
os.Exit(1)
41+
}
42+
43+
UserName = os.Getenv("USER_NAME")
44+
if UserName == "" {
45+
logger.Error("USER_NAME not set")
46+
os.Exit(1)
47+
}
48+
49+
SubscribedRepos = strings.Split(os.Getenv("SUBSCRIBED_REPOS"), ",")
50+
}

0 commit comments

Comments
 (0)