-
Notifications
You must be signed in to change notification settings - Fork 1
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 9b94746
Showing
44 changed files
with
4,678 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,12 @@ | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
*.test | ||
*.out | ||
.idea | ||
*.iml | ||
data | ||
config.yaml | ||
.cache |
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,17 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.5.0 | ||
hooks: | ||
- id: check-merge-conflict | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
- repo: https://github.com/Lucas-C/pre-commit-hooks | ||
rev: v1.1.7 | ||
hooks: | ||
- id: remove-crlf | ||
- repo: https://github.com/dnephin/pre-commit-golang | ||
rev: 0a943e8cbbdfd4a4b33f15e77c542715b4964f65 | ||
hooks: | ||
- id: go-fmt | ||
- id: go-build | ||
- id: go-imports |
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,29 @@ | ||
FROM golang:latest as builder | ||
|
||
ENV USER=appuser | ||
ENV UID=10001 | ||
|
||
RUN adduser \ | ||
--disabled-password \ | ||
--gecos "" \ | ||
--home "/nonexistent" \ | ||
--shell "/sbin/nologin" \ | ||
--no-create-home \ | ||
--uid "${UID}" \ | ||
"${USER}" | ||
|
||
WORKDIR /app | ||
COPY . /app | ||
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -trimpath -ldflags=-buildid= -o main github.com/greboid/irc/cmd/github | ||
|
||
FROM scratch | ||
|
||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
COPY --from=builder /etc/passwd /etc/passwd | ||
COPY --from=builder /etc/group /etc/group | ||
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo | ||
|
||
COPY --from=builder /app/main /irc-github | ||
EXPOSE 8080 | ||
USER appuser:appuser | ||
CMD ["/irc-github"] |
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Greg Holmes | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,36 @@ | ||
## Github IRC notifier plugin | ||
|
||
Plugin for [IRC-Bot](https://github.com/greboid/irc-bot) | ||
|
||
Receives notifications from a [Github](https://github.com/) instance and outputs them to a channel. | ||
|
||
- go build go build github.com/greboid/irc-github/v2/cmd/github | ||
- docker run greboid/irc-github | ||
|
||
#### Configuration | ||
|
||
At a bare minimum you also need to give it a channel, a github secret to verify received notifications | ||
on and an RPC token. You'll like also want to specify the bot host. | ||
|
||
Optionally you can hide any notifications about private channels, or send them to a different channel. | ||
|
||
Once configured the URL to configure in github would be <Bot URL>/github | ||
|
||
#### Example running | ||
|
||
``` | ||
--- | ||
version: "3.5" | ||
service: | ||
goplum: | ||
image: greboid/irc-github | ||
environment: | ||
RPC_HOST: bot | ||
RPC_TOKEN: <as configured on the bot> | ||
CHANNEL: #spam | ||
GITHUB_SECRET: cUCrb7HJ | ||
``` | ||
|
||
``` | ||
github -rpc-host bot -rpc-token <as configured on the bot> -channel #spam -github-secret cUCrb7HJ | ||
``` |
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,81 @@ | ||
package main | ||
|
||
//ping events | ||
type pinghook struct { | ||
} | ||
|
||
//Push events | ||
type pushhook struct { | ||
Refspec string `json:"ref"` | ||
Repository Repository `json:"repository"` | ||
Pusher Pusher `json:"pusher"` | ||
Sender Sender `json:"sender"` | ||
Forced bool `json:"forced"` | ||
Deleted bool `json:"deleted"` | ||
Created bool `json:"created"` | ||
CompareLink string `json:"compare"` | ||
Commits []Commit `json:"commits"` | ||
Baserefspec string `json:"base_ref"` | ||
} | ||
|
||
type Repository struct { | ||
FullName string `json:"full_name"` | ||
IsPrivate bool `json:"private"` | ||
} | ||
|
||
type Pusher struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
type Commit struct { | ||
ID string `json:"id"` | ||
Message string `json:"message"` | ||
URL string `json:"url"` | ||
Author Author `json:"author"` | ||
Committer Author `json:"committer"` | ||
} | ||
|
||
type Author struct { | ||
User string `json:"username"` | ||
} | ||
|
||
type Sender struct { | ||
Login string `json:"login"` | ||
} | ||
|
||
//Pull Request events | ||
type prhook struct { | ||
Action string `json:"action"` | ||
PullRequest PullRequest `json:"pull_request"` | ||
Repository Repository `json:"repository"` | ||
} | ||
|
||
type PullRequest struct { | ||
HtmlURL string `json:"html_url"` | ||
Url string `json:"url"` | ||
State string `json:"state"` | ||
Title string `json:"title"` | ||
Body string `json:"body"` | ||
User User `json:"user"` | ||
Merged string `json:"merged_at"` | ||
MergedBy User `json:"merged_by"` | ||
} | ||
|
||
type User struct { | ||
Login string `json:"login"` | ||
} | ||
|
||
//Issue events | ||
type issuehook struct { | ||
Action string `json:"action"` | ||
Issue Issue `json:"issue"` | ||
Repository Repository `json:"repository"` | ||
User User `json:"sender"` | ||
} | ||
|
||
type Issue struct { | ||
HtmlURL string `json:"html_url"` | ||
Title string `json:"title"` | ||
State string `json:"state"` | ||
User User `json:"user"` | ||
} |
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,26 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type githubIssueCommenthandler struct{} | ||
|
||
func (g *githubIssueCommenthandler) handleIssueCommentEvent(data issuehook) (messages []string) { | ||
switch data.Action { | ||
case "created": | ||
return g.handleIssueCommentCreated(data) | ||
} | ||
return []string{} | ||
} | ||
|
||
func (g *githubIssueCommenthandler) handleIssueCommentCreated(data issuehook) (messages []string) { | ||
messages = append(messages, fmt.Sprintf( | ||
"[%s] %s commented on issue %s - %s", | ||
data.Repository.FullName, | ||
data.User.Login, | ||
data.Issue.Title, | ||
data.Issue.HtmlURL, | ||
)) | ||
return | ||
} |
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,48 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/sebdah/goldie/v2" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func Test_githubissuehandler_handIssueCommentEvent_comment(t *testing.T) { | ||
g := &githubIssueCommenthandler{} | ||
hook := issuehook{} | ||
err := getTestData("issuecomments/commented_1.json", &hook) | ||
if err != nil { | ||
t.Fatal("Unable to parse example data") | ||
} | ||
messages := g.handleIssueCommentEvent(hook) | ||
if len(messages) == 0 { | ||
t.Fatal("Output expected, none provided") | ||
} | ||
} | ||
|
||
func Test_githubissuehandler_handIssueCommentEvent_unknown(t *testing.T) { | ||
g := &githubIssueCommenthandler{} | ||
hook := issuehook{} | ||
hook.Action = "ThisWillError" | ||
messages := g.handleIssueCommentEvent(hook) | ||
if len(messages) != 0 { | ||
t.Fatal("Output provided, none expected") | ||
} | ||
} | ||
|
||
func Test_githubissuehandler_handleIssueCommentCreated(t *testing.T) { | ||
tests := []string{"issuecomments/commented_1.json"} | ||
gold := goldie.New(t) | ||
for index := range tests { | ||
t.Run(tests[index], func(t *testing.T) { | ||
g := &githubIssueCommenthandler{} | ||
hook := issuehook{} | ||
err := getTestData(tests[index], &hook) | ||
if err != nil { | ||
t.Fatal("Unable to parse example data") | ||
} | ||
got := []byte(strings.Join(g.handleIssueCommentCreated(hook), "\n")) | ||
gold.Assert(t, tests[index], got) | ||
}) | ||
|
||
} | ||
} |
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,37 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type githubissuehandler struct{} | ||
|
||
func (g *githubissuehandler) handleIssueEvent(data issuehook) (messages []string) { | ||
switch data.Action { | ||
case "opened": | ||
return g.handleIssueOpened(data) | ||
case "closed": | ||
return g.handleIssueClosed(data) | ||
} | ||
return []string{} | ||
} | ||
|
||
func (g *githubissuehandler) handleIssueOpened(data issuehook) (messages []string) { | ||
messages = append(messages, fmt.Sprintf( | ||
"[%s] %s create issue: %s - %s", | ||
data.Repository.FullName, | ||
data.User.Login, | ||
data.Issue.Title, | ||
data.Issue.HtmlURL, | ||
)) | ||
return | ||
} | ||
|
||
func (g *githubissuehandler) handleIssueClosed(data issuehook) (messages []string) { | ||
messages = append(messages, fmt.Sprintf( | ||
"[%s] %s closed issue %s - %s", | ||
data.Repository.FullName, | ||
data.User.Login, | ||
data.Issue.Title, | ||
data.Issue.HtmlURL, | ||
)) | ||
return | ||
} |
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,79 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/sebdah/goldie/v2" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func Test_githubissuehandler_handIssueEvent_open(t *testing.T) { | ||
g := &githubissuehandler{} | ||
hook := issuehook{} | ||
err := getTestData("issues/create_1.json", &hook) | ||
if err != nil { | ||
t.Fatal("Unable to parse example data") | ||
} | ||
messages := g.handleIssueEvent(hook) | ||
if len(messages) == 0 { | ||
t.Fatal("Output expected, none provided") | ||
} | ||
} | ||
|
||
func Test_githubissuehandler_handIssueEvent_closed(t *testing.T) { | ||
g := &githubissuehandler{} | ||
hook := issuehook{} | ||
err := getTestData("issues/closed_1.json", &hook) | ||
if err != nil { | ||
t.Fatal("Unable to parse example data") | ||
} | ||
messages := g.handleIssueEvent(hook) | ||
if len(messages) == 0 { | ||
t.Fatal("Output expected, none provided") | ||
} | ||
} | ||
|
||
func Test_githubissuehandler_handIssueEvent_unknown(t *testing.T) { | ||
g := &githubissuehandler{} | ||
hook := issuehook{} | ||
hook.Action = "ThisWillError" | ||
messages := g.handleIssueEvent(hook) | ||
if len(messages) != 0 { | ||
t.Fatal("Output provided, none expected") | ||
} | ||
} | ||
|
||
func Test_githubissuehandler_handleIssueOpened(t *testing.T) { | ||
tests := []string{"issues/create_1.json"} | ||
gold := goldie.New(t) | ||
for index := range tests { | ||
t.Run(tests[index], func(t *testing.T) { | ||
g := &githubissuehandler{} | ||
hook := issuehook{} | ||
err := getTestData(tests[index], &hook) | ||
if err != nil { | ||
t.Fatal("Unable to parse example data") | ||
} | ||
got := []byte(strings.Join(g.handleIssueOpened(hook), "\n")) | ||
gold.Assert(t, tests[index], got) | ||
}) | ||
|
||
} | ||
} | ||
|
||
func Test_githubissuehandler_handleIssueClosed(t *testing.T) { | ||
tests := []string{"issues/closed_1.json"} | ||
gold := goldie.New(t) | ||
for index := range tests { | ||
t.Run(tests[index], func(t *testing.T) { | ||
g := &githubissuehandler{} | ||
hook := issuehook{} | ||
err := getTestData(tests[index], &hook) | ||
if err != nil { | ||
t.Fatal("Unable to parse example data") | ||
} | ||
got := []byte(strings.Join(g.handleIssueClosed(hook), "\n")) | ||
gold.Assert(t, tests[index], got) | ||
}) | ||
|
||
} | ||
} |
Oops, something went wrong.