diff options
author | Alexander Kiryukhin <alexander@kiryukhin.su> | 2019-01-31 01:02:31 +0300 |
---|---|---|
committer | Alexander Kiryukhin <alexander@kiryukhin.su> | 2019-01-31 01:02:31 +0300 |
commit | 91c16487472cb23671ffdc9c230120441f85b620 (patch) | |
tree | 7454aa0053a2b613ff02c3a75db8bc5e09d6b5b2 |
Initial commit
-rw-r--r-- | .idea/misc.xml | 6 | ||||
-rw-r--r-- | .idea/modules.xml | 8 | ||||
-rw-r--r-- | .idea/reviewbot.iml | 9 | ||||
-rw-r--r-- | .idea/workspace.xml | 263 | ||||
-rw-r--r-- | Dockerfile | 16 | ||||
-rw-r--r-- | go.mod | 13 | ||||
-rw-r--r-- | go.sum | 23 | ||||
-rw-r--r-- | main.go | 92 | ||||
-rw-r--r-- | members.go | 23 |
9 files changed, 453 insertions, 0 deletions
diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="JavaScriptSettings"> + <option name="languageLevel" value="ES6" /> + </component> +</project>
\ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a78837c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/reviewbot.iml" filepath="$PROJECT_DIR$/.idea/reviewbot.iml" /> + </modules> + </component> +</project>
\ No newline at end of file diff --git a/.idea/reviewbot.iml b/.idea/reviewbot.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/reviewbot.iml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="WEB_MODULE" version="4"> + <component name="Go" enabled="true" /> + <component name="NewModuleRootManager"> + <content url="file://$MODULE_DIR$" /> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module>
\ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..2b650eb --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,263 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ChangeListManager"> + <list default="true" id="f6d92d57-150e-493c-8334-b6907824cd50" name="Default Changelist" comment="" /> + <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> + <option name="SHOW_DIALOG" value="false" /> + <option name="HIGHLIGHT_CONFLICTS" value="true" /> + <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> + <option name="LAST_RESOLUTION" value="IGNORE" /> + </component> + <component name="FileEditorManager"> + <leaf> + <file pinned="false" current-in-tab="false"> + <entry file="file://$PROJECT_DIR$/main.go"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="419"> + <caret line="78" column="9" selection-start-line="78" selection-start-column="9" selection-end-line="78" selection-end-column="9" /> + <folding> + <element signature="e#14#71#0" expanded="true" /> + </folding> + </state> + </provider> + </entry> + </file> + <file pinned="false" current-in-tab="false"> + <entry file="file://$PROJECT_DIR$/members.go"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="182"> + <caret line="14" column="20" selection-start-line="14" selection-start-column="20" selection-end-line="14" selection-end-column="20" /> + <folding> + <element signature="e#14#37#0" expanded="true" /> + </folding> + </state> + </provider> + </entry> + </file> + <file pinned="false" current-in-tab="true"> + <entry file="file://$PROJECT_DIR$/Dockerfile"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="195"> + <caret line="15" column="20" lean-forward="true" selection-start-line="15" selection-start-column="20" selection-end-line="15" selection-end-column="20" /> + </state> + </provider> + </entry> + </file> + <file pinned="false" current-in-tab="false"> + <entry file="file://$USER_HOME$/go/pkg/mod/github.com/labstack/echo@v3.3.10+incompatible/context.go"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="187"> + <caret line="170" column="4" selection-start-line="170" selection-start-column="4" selection-end-line="170" selection-end-column="4" /> + </state> + </provider> + </entry> + </file> + <file pinned="false" current-in-tab="false"> + <entry file="file://$APPLICATION_CONFIG_DIR$/scratches/scratch_4.json"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="325"> + <caret line="25" column="4" lean-forward="true" selection-start-line="19" selection-start-column="2" selection-end-line="25" selection-end-column="4" /> + </state> + </provider> + </entry> + </file> + </leaf> + </component> + <component name="FileTemplateManagerImpl"> + <option name="RECENT_TEMPLATES"> + <list> + <option value="Go File" /> + </list> + </option> + </component> + <component name="GOROOT" path="/usr/local/Cellar/go/1.11/libexec" /> + <component name="GoLibraries"> + <option name="indexEntireGoPath" value="false" /> + </component> + <component name="IdeDocumentHistory"> + <option name="CHANGED_PATHS"> + <list> + <option value="$APPLICATION_CONFIG_DIR$/scratches/scratch_4.json" /> + <option value="$PROJECT_DIR$/main.go" /> + <option value="$PROJECT_DIR$/members.go" /> + <option value="$PROJECT_DIR$/Dockerfile" /> + </list> + </option> + </component> + <component name="ProjectFrameBounds" fullScreen="true"> + <option name="width" value="1680" /> + <option name="height" value="1050" /> + </component> + <component name="ProjectView"> + <navigator proportions="" version="1"> + <foldersAlwaysOnTop value="true" /> + </navigator> + <panes> + <pane id="Scope" /> + <pane id="ProjectPane"> + <subPane> + <expand> + <path> + <item name="reviewbot" type="b2602c69:ProjectViewProjectNode" /> + <item name="reviewbot" type="462c0819:PsiDirectoryNode" /> + </path> + </expand> + <select /> + </subPane> + </pane> + </panes> + </component> + <component name="PropertiesComponent"> + <property name="DefaultGoTemplateProperty" value="Go File" /> + <property name="WebServerToolWindowFactoryState" value="false" /> + <property name="com.intellij.ide.scratch.LRUPopupBuilder$1/New Scratch File" value="JSON" /> + <property name="go.gopath.indexing.explicitly.defined" value="true" /> + <property name="last_opened_file_path" value="$USER_HOME$" /> + <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" /> + <property name="nodejs_npm_path_reset_for_default_project" value="true" /> + <property name="settings.editor.selected.configurable" value="go.sdk" /> + </component> + <component name="RunDashboard"> + <option name="ruleStates"> + <list> + <RuleState> + <option name="name" value="ConfigurationTypeDashboardGroupingRule" /> + </RuleState> + <RuleState> + <option name="name" value="StatusDashboardGroupingRule" /> + </RuleState> + </list> + </option> + </component> + <component name="RunManager" selected="Docker.Dockerfile"> + <configuration name="go build reviewbot" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true"> + <module name="reviewbot" /> + <working_directory value="$PROJECT_DIR$" /> + <envs> + <env name="TOKEN" value="xoxp-14813661649-417577012086-538484261991-0f279706cae2fe380c76546f43d98cb2" /> + </envs> + <kind value="DIRECTORY" /> + <filePath value="$PROJECT_DIR$/main.go" /> + <directory value="$PROJECT_DIR$" /> + <method v="2" /> + </configuration> + <configuration name="Dockerfile" type="docker-deploy" factoryName="dockerfile" temporary="true" server-name="Docker"> + <deployment type="dockerfile"> + <settings> + <option name="buildOnly" value="true" /> + <option name="sourceFilePath" value="Dockerfile" /> + </settings> + </deployment> + <method v="2" /> + </configuration> + <list> + <item itemvalue="Go Build.go build reviewbot" /> + <item itemvalue="Docker.Dockerfile" /> + </list> + <recent_temporary> + <list> + <item itemvalue="Docker.Dockerfile" /> + <item itemvalue="Go Build.go build reviewbot" /> + </list> + </recent_temporary> + </component> + <component name="ToolWindowManager"> + <frame x="0" y="0" width="1680" height="1050" extended-state="0" /> + <editor active="true" /> + <layout> + <window_info id="Favorites" side_tool="true" /> + <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.24969475" /> + <window_info id="Structure" order="1" side_tool="true" weight="0.25" /> + <window_info active="true" anchor="bottom" id="Docker" visible="true" weight="0.32959184" /> + <window_info anchor="bottom" id="Database Changes" /> + <window_info anchor="bottom" id="Version Control" /> + <window_info anchor="bottom" id="Terminal" weight="0.32959184" /> + <window_info anchor="bottom" id="Event Log" side_tool="true" /> + <window_info anchor="bottom" id="Message" order="0" /> + <window_info anchor="bottom" id="Find" order="1" /> + <window_info anchor="bottom" id="Run" order="2" weight="0.32959184" /> + <window_info anchor="bottom" id="Debug" order="3" weight="0.4" /> + <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> + <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> + <window_info anchor="bottom" id="TODO" order="6" /> + <window_info anchor="right" id="Database" /> + <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" /> + <window_info anchor="right" id="Ant Build" order="1" weight="0.25" /> + <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" /> + </layout> + </component> + <component name="TypeScriptGeneratedFilesManager"> + <option name="version" value="1" /> + </component> + <component name="VgoProject"> + <integration-enabled>true</integration-enabled> + <proxy>direct</proxy> + </component> + <component name="XDebuggerManager"> + <breakpoint-manager> + <breakpoints> + <line-breakpoint enabled="true" type="DlvLineBreakpoint"> + <url>file://$PROJECT_DIR$/main.go</url> + <line>86</line> + <properties /> + <option name="timeStamp" value="3" /> + </line-breakpoint> + <line-breakpoint enabled="true" type="DlvLineBreakpoint"> + <url>file://$PROJECT_DIR$/main.go</url> + <line>77</line> + <properties /> + <option name="timeStamp" value="4" /> + </line-breakpoint> + <line-breakpoint enabled="true" type="DlvLineBreakpoint"> + <url>file://$PROJECT_DIR$/main.go</url> + <line>80</line> + <properties /> + <option name="timeStamp" value="5" /> + </line-breakpoint> + </breakpoints> + </breakpoint-manager> + </component> + <component name="editorHistoryManager"> + <entry file="file://$APPLICATION_CONFIG_DIR$/scratches/scratch_4.json"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="325"> + <caret line="25" column="4" lean-forward="true" selection-start-line="19" selection-start-column="2" selection-end-line="25" selection-end-column="4" /> + </state> + </provider> + </entry> + <entry file="file://$USER_HOME$/go/pkg/mod/github.com/labstack/echo@v3.3.10+incompatible/context.go"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="187"> + <caret line="170" column="4" selection-start-line="170" selection-start-column="4" selection-end-line="170" selection-end-column="4" /> + </state> + </provider> + </entry> + <entry file="file://$PROJECT_DIR$/main.go"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="419"> + <caret line="78" column="9" selection-start-line="78" selection-start-column="9" selection-end-line="78" selection-end-column="9" /> + <folding> + <element signature="e#14#71#0" expanded="true" /> + </folding> + </state> + </provider> + </entry> + <entry file="file://$PROJECT_DIR$/members.go"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="182"> + <caret line="14" column="20" selection-start-line="14" selection-start-column="20" selection-end-line="14" selection-end-column="20" /> + <folding> + <element signature="e#14#37#0" expanded="true" /> + </folding> + </state> + </provider> + </entry> + <entry file="file://$PROJECT_DIR$/Dockerfile"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="195"> + <caret line="15" column="20" lean-forward="true" selection-start-line="15" selection-start-column="20" selection-end-line="15" selection-end-column="20" /> + </state> + </provider> + </entry> + </component> +</project>
\ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5e60af2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# STEP 1 +FROM golang:1.11-stretch as builder +COPY . /srv/app +WORKDIR /srv/app +#get dependancies +RUN go mod download +#build the binary +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o /go/bin/app + +# STEP 2 +# start from scratch +FROM scratch +# Copy our static executable +WORKDIR /usr/app +COPY --from=builder /go/bin/app . +ENTRYPOINT ["./app"]
\ No newline at end of file @@ -0,0 +1,13 @@ +module reviewbot + +require ( + github.com/labstack/echo v3.3.10+incompatible + github.com/labstack/gommon v0.2.8 // indirect + github.com/mattn/go-colorable v0.0.9 // indirect + github.com/mattn/go-isatty v0.0.4 // indirect + github.com/stretchr/testify v1.3.0 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4 // indirect + golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664 // indirect + golang.org/x/sys v0.0.0-20190130150945-aca44879d564 // indirect +) @@ -0,0 +1,23 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg= +github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= +github.com/labstack/gommon v0.2.8 h1:JvRqmeZcfrHC5u6uVleB4NxxNbzx6gpbJiQknDbKQu0= +github.com/labstack/gommon v0.2.8/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4= +github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4 h1:gKMu1Bf6QINDnvyZuTaACm9ofY+PRh+5vFz4oxBZeF8= +github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4/go.mod h1:50wTf68f99/Zt14pr046Tgt3Lp2vLyFZKzbFXTOabXw= +golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664 h1:YbZJ76lQ1BqNhVe7dKTSB67wDrc2VPRR75IyGyyPDX8= +golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/sys v0.0.0-20190130150945-aca44879d564 h1:o6ENHFwwr1TZ9CUPQcfo1HGvLP1OPsPOTB7xCIOPNmU= +golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -0,0 +1,92 @@ +package main + +import ( + "bytes" + "encoding/json" + "errors" + "github.com/labstack/echo" + "io/ioutil" + "log" + "net/http" +) + +type event struct { + Payload string `form:"payload"` +} + +type payload struct { + Type string `json:"type" form:"type"` + Token string `json:"token"` + ActionTS string `json:"action_ts"` + + Team struct { + ID string `json:"id"` + Domain string `json:"domain"` + } + User struct { + ID string `json:"id"` + Name string `json:"name"` + } `json:"user"` + Channel struct { + ID string `json:"id"` + Name string `json:"name"` + } `json:"channel"` + CallbackID string `json:"callback_id"` + TriggerID string `json:"trigger_id"` + MessageTS string `json:"message_ts"` + Message struct { + ClientMsgID string `json:"client_msg_id"` + Type string `json:"type"` + Text string `json:"text"` + User string `json:"user"` + TS string `json:"ts"` + } `json:"message"` + ResponseUrl string `json:"response_url"` +} + +type message struct { + Text string `json:"text"` + ResponseType string `json:"response_type"` + Attachments []Attachment `json:"attachments"` +} +type Attachment struct { + Color string `json:"color"` + Text string `json:"text"` +} + +func main() { + e := echo.New() + e.POST("/events-endpoint", func(c echo.Context) error { + ev := &event{} + c.Bind(ev) + pl := &payload{} + if err := json.Unmarshal([]byte(ev.Payload), pl); err != nil { + log.Println(err) + return err + } + + member := getRandomMember() + text := "Назначен: " + member + jm := message{ + Text: pl.Message.Text, + ResponseType: "in_channel", + Attachments: []Attachment{{Text: text, Color: "#36a64f"}}, + } + b, _ := json.Marshal(jm) + resp, err := http.DefaultClient.Post(pl.ResponseUrl, "application/json", bytes.NewReader(b)) + if err != nil { + return err + } + if resp.StatusCode >= 300 || resp.StatusCode < 200 { + return errors.New("unexpected status " + resp.Status) + } + defer resp.Body.Close() + s, _ := ioutil.ReadAll(resp.Body) + log.Println(string(s)) + + return nil + }) + if err := e.Start(":3000"); err != nil { + log.Fatalln(err) + } +} diff --git a/members.go b/members.go new file mode 100644 index 0000000..2886bed --- /dev/null +++ b/members.go @@ -0,0 +1,23 @@ +package main + +import ( + "math/rand" + "time" +) + +func getRandomMember() string { + rand.Seed(time.Now().Unix()) + team := []string{ + "<@U8UJT0UJX>", + "<@UCF7JA5CZ>", + "<@UC86HMG1G>", + "<@UCFHM9G04>", + "<@UC9GZ0C2J>", + } + + n := rand.Int() % len(team) + member := team[n] + + return member +} + |