-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
df7774f
commit fd34591
Showing
24 changed files
with
944 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,106 @@ | ||
name: Build Docker Image (amd64 & arm64) | ||
on: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
ImageBuild: | ||
name: Build Wakatime-to-slack-status Custom Docker Image (amd64 & arm64) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Slack notification of build start | ||
uses: rtCamp/action-slack-notify@v2 | ||
env: | ||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
SLACK_USERNAME: GitHub Actions | ||
SLACK_COLOR: "#4381de" | ||
SLACK_ICON: "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" | ||
SLACK_TITLE: Start Wakatime-to-slack-status image build | ||
SLACK_MESSAGE: | | ||
Run number : #${{ github.run_number }} | ||
- name: Check out | ||
uses: actions/checkout@v3 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: walnuts1018 | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/[email protected] | ||
with: | ||
version: latest | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx | ||
restore-keys: | | ||
${{ runner.os }}-buildx | ||
- name: Get Tag from Release | ||
run: echo "ImageTag=${GITHUB_REF##*/}" >> $GITHUB_ENV | ||
|
||
- name: Build and push Docker images | ||
uses: docker/[email protected] | ||
if: github.event_name == 'release' | ||
with: | ||
push: true | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache | ||
tags: | | ||
ghcr.io/walnuts1018/wakatime-to-slack-status:latest | ||
ghcr.io/walnuts1018/wakatime-to-slack-status:${{ env.ImageTag }} | ||
- name: Build and push Docker images | ||
uses: docker/[email protected] | ||
if: github.event_name != 'release' | ||
with: | ||
push: true | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
tags: | | ||
ghcr.io/walnuts1018/wakatime-to-slack-status:test-latest | ||
ghcr.io/walnuts1018/wakatime-to-slack-status:test-${{ github.sha }}-${{ github.run_number }} | ||
SucceessNotification: | ||
if: ${{ success() }} | ||
name: Send Success Message | ||
needs: [ImageBuild] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Send Message to Slack | ||
uses: rtCamp/action-slack-notify@v2 | ||
env: | ||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
SLACK_USERNAME: GitHub Actions | ||
SLACK_ICON: "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" | ||
SLACK_TITLE: Wakatime-to-slack-status id:mage build succeeded | ||
SLACK_MESSAGE: | | ||
Run number : #${{ github.run_number }} | ||
Image tag : ${{ github.sha }}-${{ github.run_number }} | ||
Image URL : | ||
FailureAlert: | ||
if: ${{ failure() }} | ||
name: Notify failure | ||
needs: [ImageBuild] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Send Failure Alert to Slack | ||
uses: rtCamp/action-slack-notify@v2 | ||
env: | ||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
SLACK_USERNAME: GitHub Actions | ||
SLACK_ICON: "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" | ||
SLACK_TITLE: Wakatime-to-slack-status image build failed | ||
SLACK_COLOR: danger | ||
SLACK_MESSAGE: 'Run number : #${{ github.run_number }}' |
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 |
---|---|---|
|
@@ -19,3 +19,4 @@ | |
|
||
# Go workspace file | ||
go.work | ||
.env |
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 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Launch Package", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "auto", | ||
"program": "${workspaceFolder}/main.go" | ||
} | ||
] | ||
} |
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 @@ | ||
FROM golang:1.21 as builder | ||
ENV ROOT=/build | ||
RUN mkdir ${ROOT} | ||
WORKDIR ${ROOT} | ||
|
||
COPY ./ ./ | ||
RUN go get | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux go build -o main $ROOT/main.go && chmod +x ./main | ||
|
||
FROM alpine:3 | ||
WORKDIR /app | ||
|
||
COPY --from=builder /build/main ./ | ||
COPY --from=builder /build/templates/ /app/templates/ | ||
COPY --from=builder /build/assets/ /app/assets/ | ||
COPY --from=builder /usr/share/zoneinfo/Asia/Tokyo /usr/share/zoneinfo/Asia/Tokyo | ||
CMD ["./main"] | ||
LABEL org.opencontainers.image.source = "https://github.com/walnuts1018/wakatime-to-slack-status" |
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,25 @@ | ||
body{ | ||
background-color: #f2f2f2; | ||
} | ||
|
||
.card { | ||
margin: 50px auto; | ||
padding: 10px 30px; | ||
width: 500px; | ||
text-align: center; | ||
background-color: white; | ||
border-radius: 12px; | ||
box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.3); | ||
|
||
} | ||
|
||
.error { | ||
font-family: Consolas, 'Courier New', Courier, Monaco, monospace; | ||
display:inline-block; | ||
padding: 10px 30px; | ||
background-color: #262626; | ||
border-radius: 10px; | ||
color: #dfdfdf; | ||
max-width: 450px; | ||
overflow-wrap: break-word; | ||
} |
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,55 @@ | ||
package config | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log/slog" | ||
"os" | ||
"reflect" | ||
|
||
"github.com/joho/godotenv" | ||
) | ||
|
||
type Config_t struct { | ||
WakatimeAppID string `env:"WAKATIME_APP_ID"` | ||
WakatimeAppSecret string `env:"WAKATIME_CLIENT_SECRET"` | ||
CookieSecret string `env:"COOKIE_SECRET"` | ||
|
||
PSQLEndpoint string `env:"PSQL_ENDPOINT"` | ||
PSQLPort string `env:"PSQL_PORT"` | ||
PSQLDatabase string `env:"PSQL_DATABASE"` | ||
PSQLUser string `env:"PSQL_USER"` | ||
PSQLPassword string `env:"PSQL_PASSWORD"` | ||
|
||
SlackAccessToken string `env:"SLACK_ACCESS_TOKEN"` | ||
|
||
ServerPort string | ||
} | ||
|
||
var Config = Config_t{} | ||
|
||
func LoadConfig() error { | ||
serverport := flag.String("port", "8080", "server port") | ||
flag.Parse() | ||
Config.ServerPort = *serverport | ||
|
||
err := godotenv.Load(".env") | ||
if err != nil { | ||
slog.Warn("Error loading .env file") | ||
} | ||
|
||
t := reflect.TypeOf(Config) | ||
for i := 0; i < t.NumField(); i++ { | ||
fieldName := t.Field(i).Name | ||
tag, ok := t.Field(i).Tag.Lookup("env") | ||
if !ok { | ||
continue | ||
} | ||
v, ok := os.LookupEnv(tag) | ||
if !ok { | ||
return fmt.Errorf("%s is not set", tag) | ||
} | ||
reflect.ValueOf(&Config).Elem().FieldByName(fieldName).SetString(v) | ||
} | ||
return nil | ||
} |
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 @@ | ||
version: '3' | ||
services: | ||
postgres: | ||
image: postgres:16 | ||
container_name: psql | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- ./psql:/docker-entrypoint-initdb.d | ||
environment: | ||
POSTGRES_USER: "postgres" | ||
POSTGRES_PASSWORD: "postgres" |
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,4 @@ | ||
package domain | ||
|
||
type SlackClient interface { | ||
} |
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,8 @@ | ||
package domain | ||
|
||
type TokenStore interface { | ||
SaveOAuth2Token(OAuth2Token) error | ||
GetOAuth2Token() (OAuth2Token, error) | ||
UpdateOAuth2Token(token OAuth2Token) error | ||
Close() error | ||
} |
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,30 @@ | ||
package domain | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
type OAuth2Token struct { | ||
AccessToken string | ||
RefreshToken string | ||
Expiry time.Time | ||
CreatedAt time.Time | ||
UpdatedAt time.Time | ||
} | ||
|
||
type WakatimeClient interface { | ||
Auth(state string) string | ||
Callback(ctx context.Context, code string) (OAuth2Token, error) | ||
SetToken(ctx context.Context, tokenStore TokenStore) error | ||
Languages(ctx context.Context) ([]Language, error) | ||
} | ||
|
||
type Language struct { | ||
Id string `json:"id"` //unique id of this language | ||
Name string `json:"name"` //human readable name of this language | ||
Color string `json:"color"` //hex color code, used when displaying this language on WakaTime charts | ||
IsVerified bool `json:"is_verified"` //whether this language is verified, by GitHub’s linguist or manually by WakaTime admins | ||
CreatedAt string `json:"created_at"` //time when this language was created in ISO 8601 format | ||
ModifiedAt string `json:"modified_at"` //time when this language was last modified in ISO 8601 format | ||
} |
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,45 @@ | ||
module github.com/walnuts1018/wakatime-to-slack-profile | ||
|
||
go 1.21.1 | ||
|
||
require ( | ||
github.com/gin-contrib/sessions v0.0.5 | ||
github.com/gin-gonic/gin v1.9.1 | ||
github.com/joho/godotenv v1.5.1 | ||
github.com/lib/pq v1.10.9 | ||
github.com/slack-go/slack v0.12.3 | ||
golang.org/x/oauth2 v0.12.0 | ||
) | ||
|
||
require ( | ||
github.com/bytedance/sonic v1.9.1 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.14.0 // indirect | ||
github.com/goccy/go-json v0.10.2 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/gorilla/context v1.1.1 // indirect | ||
github.com/gorilla/securecookie v1.1.1 // indirect | ||
github.com/gorilla/sessions v1.2.1 // indirect | ||
github.com/gorilla/websocket v1.4.2 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect | ||
github.com/leodido/go-urn v1.2.4 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.8 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.11 // indirect | ||
golang.org/x/arch v0.3.0 // indirect | ||
golang.org/x/crypto v0.13.0 // indirect | ||
golang.org/x/net v0.15.0 // indirect | ||
golang.org/x/sys v0.12.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.