Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
yakumioto committed Apr 12, 2019
0 parents commit b473275
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
kind: pipeline
name: default

steps:
- name: build
image: golang:1.12-alpine
commands:
- GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w" -o serverchan serverchan.go
when:
event:
- tag

- name: build-image
image: plugins/docker
settings:
username: yakumioto
password:
from_secret: docker_pwd
repo: yakumioto/drone-serverchan
auto_tag: true
when:
event:
- tag

- name: sendmsg
image: yakumioto/drone-serverchan
settings:
key:
from_secret: serverchan_key
text: succeeded
desp: docker build yakumioto/serverchan
when:
event:
- tag
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Created by .ignore support plugin (hsz.mobi)
### Go template
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM alpine:3.9

LABEL maintainer="Mioto <[email protected]>"

RUN apk update && apk add --no-cache ca-certificates

WORKDIR /drone/src

COPY serverchan /usr/local/bin/serverchan

ENTRYPOINT ["serverchan"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Yaku Mioto

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.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Drone ServerChan(Server酱)

[![Build Status](https://drone.mioto.me/api/badges/yakumioto/drone-serverchan/status.svg)](https://drone.mioto.me/yakumioto/drone-serverchan)
![Go Report](https://goreportcard.com/badge/github.com/yakumioto/drone-serverchan)
![Docker Pulls](https://img.shields.io/docker/pulls/yakumioto/serverchan.svg)

drone ServerChan(Server酱) 微信消息通知插件

## 简介

基于 [ServerChan(Server酱)](http://sc.ftqq.com/3.version) 封装的微信消息通知插件

## 栗子

明文 key 配置

```yml
---
kind: pipeline
name: default

steps:
- name: send-wechat
image: yakumioto/serverchan
settings:
key: {your key}
text: {消息标题}
desp: {消息内容 支持MarkDown}
```
密文 key 配置
```yml
---
kind: pipeline
name: default

steps:
- name: send-wechat
image: yakumioto/serverchan
settings:
key:
from_secret: {your key}
text: {消息标题}
desp: {消息内容 支持MarkDown}
```
26 changes: 26 additions & 0 deletions example.drone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Plaintext key
---
kind: pipeline
name: default

steps:
- name: send-wechat
image: yakumioto/serverchan
settings:
key: "{your key}"
text: "{titel}"
desp: "{content}"

# Secrets Key
---
kind: pipeline
name: default

steps:
- name: send-wechat
image: yakumioto/serverchan
settings:
key:
from_secret: key
text: "{titel}"
desp: "{content}"
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/yakumioto/drone-serverchan

go 1.12
39 changes: 39 additions & 0 deletions serverchan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"fmt"
"log"
"net/http"
"net/url"
"os"
"strings"
)

var (
key string
text string
desp string
)

func init() {
key = os.Getenv("PLUGIN_KEY")
text = os.Getenv("PLUGIN_TEXT")
desp = os.Getenv("PLUGIN_DESP")
}

func main() {
if key == "" || text == "" {
log.Fatalln("key or text is required")
}

reqMsg := &url.Values{
"text": []string{text},
"desp": []string{desp},
}

reqURL := fmt.Sprintf("https://sc.ftqq.com/%s.send", key)
_, err := http.Post(reqURL, "application/x-www-form-urlencoded", strings.NewReader(reqMsg.Encode()))
if err != nil {
log.Fatalln("post error: ", err)
}
}

0 comments on commit b473275

Please sign in to comment.