Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
7fa3553da6 | |||
14581dbe83 | |||
3053c62fa8 | |||
880ad68663 | |||
91f4676118 | |||
e315c37bb6 | |||
c4ff0acc8a |
24
.drone.yml
Normal file
24
.drone.yml
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: build
|
||||
|
||||
steps:
|
||||
- name: lint
|
||||
image: code.pztrn.name/containers/mirror/golangci/golangci-lint:v1.46.2
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
commands:
|
||||
- golangci-lint run
|
||||
|
||||
- name: docker
|
||||
image: code.pztrn.name/containers/mirror/plugins/docker:20.13.0
|
||||
when:
|
||||
branch: ["master"]
|
||||
settings:
|
||||
registry: code.pztrn.name
|
||||
username: drone
|
||||
password:
|
||||
from_secret: drone_secret
|
||||
repo: code.pztrn.name/apps/periodicator
|
||||
auto_tag: true
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
*DS_Store*
|
||||
.idea
|
||||
.vscode
|
||||
config.yaml
|
||||
release
|
||||
|
@ -16,6 +16,8 @@ linters:
|
||||
- testpackage
|
||||
# Crashes a lot.
|
||||
- gci
|
||||
# Deprecated.
|
||||
- exhaustivestruct
|
||||
linters-settings:
|
||||
lll:
|
||||
line-length: 128
|
||||
|
@ -1,4 +1,4 @@
|
||||
FROM golang:1.17.1-alpine AS build
|
||||
FROM code.pztrn.name/containers/mirror/golang:1.18.3-alpine AS build
|
||||
|
||||
WORKDIR /go/src/go.dev.pztrn.name/periodicator
|
||||
COPY . .
|
||||
@ -6,7 +6,7 @@ COPY . .
|
||||
ENV CGO_ENABLED=0
|
||||
RUN apk add make && make build
|
||||
|
||||
FROM alpine:latest
|
||||
FROM code.pztrn.name/containers/mirror/alpine:3.16.0
|
||||
LABEL maintainer="Stanislav N. <pztrn@pztrn.name>"
|
||||
|
||||
COPY --from=build /go/src/go.dev.pztrn.name/periodicator/periodicator /usr/local/bin/periodicator
|
||||
|
@ -17,7 +17,7 @@ Head over releases page, grab your binary and configure your system to start bin
|
||||
Compose a configuration file (read below) and add this to your cron:
|
||||
|
||||
```shell
|
||||
docker run --rm -v ./config.yaml:/periodicator.yaml registry.gitlab.pztrn.name/pztrn/periodicator:latest
|
||||
docker run --rm -v ./config.yaml:/periodicator.yaml pztrn/periodicator:latest
|
||||
```
|
||||
|
||||
## Configuring
|
||||
|
1
go.mod
1
go.mod
@ -9,7 +9,6 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/adhocore/gronx v0.2.5 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -33,8 +33,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/adhocore/gronx v0.2.5 h1:trVgNYPle0IcsGDt0XGz78zN8Soek0YrcQtQ+Cs+jko=
|
||||
github.com/adhocore/gronx v0.2.5/go.mod h1:7oUY1WAU8rEJWmAxXR2DN0JaO4gi9khSgKjiRypqteg=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
|
@ -45,12 +45,12 @@ func Parse() *Config {
|
||||
panic("Failed to read configuration file data: " + readErr.Error())
|
||||
}
|
||||
|
||||
// nolint:exhaustivestruct
|
||||
c := &Config{}
|
||||
// nolint:exhaustruct
|
||||
cfg := &Config{}
|
||||
|
||||
if err := yaml.Unmarshal(data, c); err != nil {
|
||||
if err := yaml.Unmarshal(data, cfg); err != nil {
|
||||
panic("Failed to unmarshal YAML data: " + err.Error())
|
||||
}
|
||||
|
||||
return c
|
||||
return cfg
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ type Client struct {
|
||||
|
||||
// NewGitlabClient creates new Gitlab's client controlling structure.
|
||||
func NewGitlabClient(cfg *Config) *Client {
|
||||
// nolint:exhaustivestruct
|
||||
// nolint:exhaustruct
|
||||
c := &Client{
|
||||
config: cfg,
|
||||
}
|
||||
@ -43,7 +43,7 @@ func (c *Client) GetClient() *gitlab.Client {
|
||||
// GetIssuesByTitle returns list of issues that matches passed title in specific
|
||||
// project.
|
||||
func (c *Client) GetIssuesByTitle(projectID int, title string) ([]*gitlab.Issue, error) {
|
||||
// nolint:exhaustivestruct
|
||||
// nolint:exhaustruct
|
||||
issues, resp, err := c.client.Issues.ListProjectIssues(projectID, &gitlab.ListProjectIssuesOptions{
|
||||
ListOptions: gitlab.ListOptions{
|
||||
PerPage: 1000,
|
||||
|
@ -11,15 +11,13 @@ import (
|
||||
|
||||
// BaseTask is a base task structure.
|
||||
type BaseTask struct {
|
||||
executionStartTimestamp time.Time
|
||||
client *gitlab.Client
|
||||
|
||||
projectID int
|
||||
title string
|
||||
body string
|
||||
tags []string
|
||||
|
||||
executionStartTimestamp time.Time
|
||||
cron string
|
||||
tags []string
|
||||
projectID int
|
||||
dueIn time.Duration
|
||||
}
|
||||
|
||||
@ -125,7 +123,7 @@ func (b *BaseTask) Run() {
|
||||
|
||||
b.log("Found no opened tasks and task should be created, doing so. Task deadline: " + nextDeadlineTS.String())
|
||||
|
||||
// nolint:exhaustivestruct
|
||||
// nolint:exhaustruct
|
||||
err := b.client.CreateIssue(b.projectID, &g.CreateIssueOptions{
|
||||
Title: &b.title,
|
||||
Description: &b.body,
|
||||
|
@ -5,12 +5,12 @@ import "time"
|
||||
// Config is a task's configuration as should be defined in configuration file.
|
||||
// nolint:tagliatelle
|
||||
type Config struct {
|
||||
ProjectID int `yaml:"project_id"`
|
||||
ExecutionStart TaskStartTime `yaml:"execution_start"`
|
||||
Title string `yaml:"title"`
|
||||
Body string `yaml:"body"`
|
||||
Tags []string `yaml:"tags"`
|
||||
ExecutionStart TaskStartTime `yaml:"execution_start"`
|
||||
Cron string `yaml:"cron"`
|
||||
Tags []string `yaml:"tags"`
|
||||
ProjectID int `yaml:"project_id"`
|
||||
DueIn time.Duration `yaml:"due_in"`
|
||||
}
|
||||
|
||||
@ -30,14 +30,14 @@ func (tts *TaskStartTime) UnmarshalYAML(unmarshal func(interface{}) error) error
|
||||
return err
|
||||
}
|
||||
|
||||
t, err := time.Parse("2006-01-02 15:04:05", timeData)
|
||||
timeField, err := time.Parse("2006-01-02 15:04:05", timeData)
|
||||
if err != nil {
|
||||
// ToDo: fix it!
|
||||
// nolint:wrapcheck
|
||||
return err
|
||||
}
|
||||
|
||||
tts.ts = t
|
||||
tts.ts = timeField
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
// PrintCreationTSes prints tasks creation timestamps.
|
||||
func PrintCreationTSes(client *gitlab.Client, tasks []Config) {
|
||||
for _, task := range tasks {
|
||||
t := &BaseTask{
|
||||
taskData := &BaseTask{
|
||||
client: client,
|
||||
projectID: task.ProjectID,
|
||||
title: task.Title,
|
||||
@ -20,19 +20,19 @@ func PrintCreationTSes(client *gitlab.Client, tasks []Config) {
|
||||
|
||||
// Get similar tasks.
|
||||
// ToDo: refactor?
|
||||
issues, err := t.getIssues()
|
||||
issues, err := taskData.getIssues()
|
||||
if err != nil {
|
||||
panic("Error while getting issues from Gitlab: " + err.Error())
|
||||
}
|
||||
|
||||
t.log(t.getNextCreationTimestamp(t.getLastCreationTimestamp(issues)).String())
|
||||
taskData.log(taskData.getNextCreationTimestamp(taskData.getLastCreationTimestamp(issues)).String())
|
||||
}
|
||||
}
|
||||
|
||||
// Process processes passed tasks.
|
||||
func Process(client *gitlab.Client, tasks []Config) {
|
||||
for _, task := range tasks {
|
||||
t := &BaseTask{
|
||||
taskData := &BaseTask{
|
||||
client: client,
|
||||
projectID: task.ProjectID,
|
||||
title: task.Title,
|
||||
@ -43,6 +43,6 @@ func Process(client *gitlab.Client, tasks []Config) {
|
||||
dueIn: task.DueIn,
|
||||
}
|
||||
|
||||
t.Run()
|
||||
taskData.Run()
|
||||
}
|
||||
}
|
||||
|
6
main.go
6
main.go
@ -29,12 +29,12 @@ func main() {
|
||||
|
||||
cfg := config.Parse()
|
||||
|
||||
c := gitlab.NewGitlabClient(&cfg.Gitlab)
|
||||
gitlabClient := gitlab.NewGitlabClient(&cfg.Gitlab)
|
||||
|
||||
if *showNextCreationTS {
|
||||
tasks.PrintCreationTSes(c, cfg.Tasks)
|
||||
tasks.PrintCreationTSes(gitlabClient, cfg.Tasks)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
tasks.Process(c, cfg.Tasks)
|
||||
tasks.Process(gitlabClient, cfg.Tasks)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user