Skip to content

Commit 41ca5a4

Browse files
committed
cmd/app: Scaffold GitHub application
Signed-off-by: Stephen Augustus <[email protected]>
1 parent 748fe09 commit 41ca5a4

File tree

3 files changed

+130
-26
lines changed

3 files changed

+130
-26
lines changed

cmd/app/main.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright 2023 uwu-tools Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
17+
// Derived from https://github.com/airconduct/go-probot/blob/main/example/main.go.
18+
package main
19+
20+
import (
21+
"context"
22+
23+
"github.com/airconduct/go-probot"
24+
probotgh "github.com/airconduct/go-probot/github"
25+
"github.com/google/go-github/v48/github"
26+
"github.com/spf13/pflag"
27+
)
28+
29+
func main() {
30+
app := probot.NewGithubAPP()
31+
app.AddFlags(pflag.CommandLine)
32+
pflag.Parse()
33+
34+
// Add a handler for events "issue_comment.created"
35+
app.On(probotgh.Event.IssueComment_created).WithHandler(
36+
probotgh.IssueCommentHandler(
37+
func(ctx probotgh.IssueCommentContext) {
38+
payload := ctx.Payload()
39+
ctx.Logger().Info("Get IssueComment event", "payload", payload)
40+
owner := payload.Repo.Owner.GetLogin()
41+
repo := payload.Repo.GetName()
42+
issueNumber := *payload.Issue.Number
43+
44+
// If any error happen, the error message will be logged and sent as response
45+
ctx.Must(
46+
ctx.Client().Issues.CreateComment(
47+
ctx, owner, repo, issueNumber, &github.IssueComment{
48+
Body: github.String("Reply to this comment."),
49+
},
50+
),
51+
)
52+
},
53+
),
54+
)
55+
56+
// Add a handler for multiple events
57+
app.On(
58+
probotgh.Event.PullRequest_opened, // pull_request.opened
59+
probotgh.Event.PullRequest_edited, // pull_request.edited
60+
probotgh.Event.PullRequest_synchronize, // pull_request.synchronize
61+
probotgh.Event.PullRequest_labeled, // pull_request.labeled
62+
probotgh.Event.PullRequest_assigned, // pull_request.assigned
63+
).WithHandler(probotgh.PullRequestHandler(
64+
func(ctx probotgh.PullRequestContext) {
65+
payload := ctx.Payload()
66+
ctx.Logger().Info(
67+
"Do something",
68+
"action",
69+
payload.GetAction(),
70+
"PullRequest labels",
71+
payload.PullRequest.Labels,
72+
)
73+
},
74+
))
75+
76+
if err := app.Run(context.Background()); err != nil {
77+
panic(err)
78+
}
79+
}

go.mod

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ go 1.18
55
replace k8s.io/client-go => k8s.io/client-go v0.24.10
66

77
require (
8+
github.com/airconduct/go-probot v0.0.2
89
github.com/caarlos0/env/v6 v6.10.1
910
github.com/ghodss/yaml v1.0.0
1011
github.com/google/go-cmp v0.5.9
12+
github.com/google/go-github/v48 v48.2.0
1113
github.com/sethvargo/go-githubactions v1.1.0
1214
github.com/sirupsen/logrus v1.9.0
1315
github.com/spf13/cobra v1.6.1
16+
github.com/spf13/pflag v1.0.5
1417
k8s.io/apimachinery v0.24.10
1518
k8s.io/test-infra v0.0.0-20230116172652-b51567b824d9
1619
sigs.k8s.io/release-utils v0.7.3
@@ -31,18 +34,19 @@ require (
3134
github.com/Azure/go-autorest/logger v0.2.1 // indirect
3235
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
3336
github.com/GoogleCloudPlatform/testgrid v0.0.123 // indirect
34-
github.com/PuerkitoBio/purell v1.1.1 // indirect
35-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
3637
github.com/andygrunwald/go-jira v1.14.0 // indirect
3738
github.com/aws/aws-sdk-go v1.38.49 // indirect
3839
github.com/beorn7/perks v1.0.1 // indirect
3940
github.com/blendle/zapdriver v1.3.1 // indirect
41+
github.com/bradleyfalzon/ghinstallation v1.1.1 // indirect
4042
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
4143
github.com/cespare/xxhash/v2 v2.1.2 // indirect
4244
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
4345
github.com/davecgh/go-spew v1.1.1 // indirect
46+
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
4447
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 // indirect
45-
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
48+
github.com/emicklei/go-restful-openapi/v2 v2.9.1 // indirect
49+
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
4650
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
4751
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
4852
github.com/fatih/structs v1.1.0 // indirect
@@ -51,8 +55,10 @@ require (
5155
github.com/go-kit/log v0.1.0 // indirect
5256
github.com/go-logfmt/logfmt v0.5.0 // indirect
5357
github.com/go-logr/logr v1.2.3 // indirect
58+
github.com/go-logr/zapr v1.2.3 // indirect
5459
github.com/go-openapi/jsonpointer v0.19.5 // indirect
55-
github.com/go-openapi/jsonreference v0.19.6 // indirect
60+
github.com/go-openapi/jsonreference v0.20.0 // indirect
61+
github.com/go-openapi/spec v0.20.7 // indirect
5662
github.com/go-openapi/swag v0.21.1 // indirect
5763
github.com/gogo/protobuf v1.3.2 // indirect
5864
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
@@ -63,6 +69,7 @@ require (
6369
github.com/google/btree v1.0.1 // indirect
6470
github.com/google/gnostic v0.5.7-v3refs // indirect
6571
github.com/google/go-containerregistry v0.8.1-0.20220216220642-00c59d91847c // indirect
72+
github.com/google/go-github/v29 v29.0.2 // indirect
6673
github.com/google/go-querystring v1.1.0 // indirect
6774
github.com/google/gofuzz v1.2.1-0.20210504230335-f78f29fc09ea // indirect
6875
github.com/google/uuid v1.3.0 // indirect
@@ -95,19 +102,18 @@ require (
95102
github.com/prometheus/statsd_exporter v0.21.0 // indirect
96103
github.com/rogpeppe/go-internal v1.9.0 // indirect
97104
github.com/sethvargo/go-envconfig v0.8.0 // indirect
98-
github.com/shurcooL/githubv4 v0.0.0-20210725200734-83ba7b4c9228 // indirect
99-
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect
100-
github.com/spf13/pflag v1.0.5 // indirect
105+
github.com/shurcooL/githubv4 v0.0.0-20221229060216-a8d4a561cc93 // indirect
106+
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29 // indirect
101107
github.com/tektoncd/pipeline v0.36.0 // indirect
102108
github.com/trivago/tgo v1.0.7 // indirect
103109
go.opencensus.io v0.23.0 // indirect
104110
go.uber.org/atomic v1.9.0 // indirect
105111
go.uber.org/multierr v1.7.0 // indirect
106-
go.uber.org/zap v1.19.1 // indirect
112+
go.uber.org/zap v1.24.0 // indirect
107113
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
108114
gocloud.dev v0.19.0 // indirect
109115
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
110-
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
116+
golang.org/x/net v0.4.0 // indirect
111117
golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb // indirect
112118
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
113119
golang.org/x/sys v0.3.0 // indirect
@@ -120,7 +126,7 @@ require (
120126
google.golang.org/appengine v1.6.7 // indirect
121127
google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac // indirect
122128
google.golang.org/grpc v1.47.0 // indirect
123-
google.golang.org/protobuf v1.28.0 // indirect
129+
google.golang.org/protobuf v1.28.1 // indirect
124130
gopkg.in/fsnotify.v1 v1.4.7 // indirect
125131
gopkg.in/inf.v0 v0.9.1 // indirect
126132
gopkg.in/yaml.v2 v2.4.0 // indirect

0 commit comments

Comments
 (0)