-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
11 changed files
with
198 additions
and
39 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
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
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
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,3 @@ | ||
.PHONY: run | ||
run: | ||
dev_appserver.py --port 3000 app.yaml |
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
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
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,19 @@ | ||
TARGET := jira-to-slack | ||
VERSION := v0.0.0 | ||
LDFLAGS := -X main.version=$(VERSION) | ||
|
||
all: $(TARGET) | ||
|
||
$(TARGET): $(wildcard *.go) | ||
GOOS=linux GOARCH=amd64 go build -o $@ -ldflags "$(LDFLAGS)" | ||
|
||
.PHONY: run | ||
run: $(TARGET) | ||
sam local start-api | ||
|
||
packaged.yaml: $(TARGET) | ||
sam package --template-file template.yaml --output-template-file $@ --s3-bucket $(SAM_S3_BUCKET_NAME) | ||
|
||
.PHONY: deploy | ||
deploy: packaged.yaml | ||
sam deploy --template-file $< --stack-name $(TARGET) --capabilities CAPABILITY_IAM |
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,80 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
"github.com/int128/jira-to-slack/pkg/handlers" | ||
"github.com/int128/jira-to-slack/pkg/jira" | ||
"github.com/int128/jira-to-slack/pkg/usecases" | ||
) | ||
|
||
func handleIndex(_ context.Context, r events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { | ||
params, err := handlers.ParseWebhookParams(r.MultiValueQueryStringParameters) | ||
if err != nil { | ||
return events.APIGatewayProxyResponse{ | ||
StatusCode: http.StatusBadRequest, | ||
Body: err.Error(), | ||
}, nil | ||
} | ||
return events.APIGatewayProxyResponse{ | ||
StatusCode: http.StatusOK, | ||
Body: fmt.Sprintf("Parameter=%+v", params), | ||
}, nil | ||
} | ||
|
||
func handleWebhook(ctx context.Context, r events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { | ||
params, err := handlers.ParseWebhookParams(r.MultiValueQueryStringParameters) | ||
if err != nil { | ||
return events.APIGatewayProxyResponse{ | ||
StatusCode: http.StatusBadRequest, | ||
Body: err.Error(), | ||
}, nil | ||
} | ||
var event jira.Event | ||
if err := json.Unmarshal([]byte(r.Body), &event); err != nil { | ||
return events.APIGatewayProxyResponse{ | ||
StatusCode: http.StatusBadRequest, | ||
Body: fmt.Sprintf("could not decode json of response body: %s", err), | ||
}, nil | ||
} | ||
in := usecases.WebhookIn{ | ||
JiraEvent: &event, | ||
SlackWebhookURL: params.Webhook, | ||
SlackUsername: params.Username, | ||
SlackIcon: params.Icon, | ||
SlackDialect: params.Dialect, | ||
} | ||
var u usecases.Webhook | ||
if err := u.Do(ctx, in); err != nil { | ||
return events.APIGatewayProxyResponse{ | ||
StatusCode: http.StatusInternalServerError, | ||
Body: err.Error(), | ||
}, nil | ||
} | ||
return events.APIGatewayProxyResponse{ | ||
StatusCode: http.StatusOK, | ||
Body: "OK", | ||
}, nil | ||
} | ||
|
||
func handler(ctx context.Context, r events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { | ||
if r.HTTPMethod == "GET" { | ||
return handleIndex(ctx, r) | ||
} | ||
if r.HTTPMethod == "POST" { | ||
return handleWebhook(ctx, r) | ||
} | ||
return events.APIGatewayProxyResponse{ | ||
StatusCode: http.StatusMethodNotAllowed, | ||
Body: "Method Not Allowed", | ||
}, nil | ||
} | ||
|
||
func main() { | ||
lambda.Start(handler) | ||
} |
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,39 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Transform: AWS::Serverless-2016-10-31 | ||
Description: jira-to-slack | ||
|
||
Globals: | ||
Function: | ||
Timeout: 5 | ||
|
||
Resources: | ||
JiraToSlackFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
CodeUri: . | ||
Handler: jira-to-slack | ||
Runtime: go1.x | ||
Tracing: Active | ||
Events: | ||
# https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api | ||
Index: | ||
Type: Api | ||
Properties: | ||
Path: / | ||
Method: GET | ||
Webhook: | ||
Type: Api | ||
Properties: | ||
Path: / | ||
Method: POST | ||
|
||
Outputs: | ||
JiraToSlackAPI: | ||
Description: "API Gateway endpoint URL for JiraToSlackFunction" | ||
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/" | ||
JiraToSlackFunction: | ||
Description: "JiraToSlackFunction function" | ||
Value: !GetAtt JiraToSlackFunction.Arn | ||
HelloWorldFunctionIamRole: | ||
Description: "Implicit IAM Role created for JiraToSlackFunction function" | ||
Value: !GetAtt JiraToSlackFunctionRole.Arn |
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
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