Compare commits

..

No commits in common. "master" and "v0.2.0" have entirely different histories.

13 changed files with 33 additions and 55 deletions

@ -1,24 +0,0 @@
---
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,5 +1,4 @@
*DS_Store*
.idea
.vscode
config.yaml
release

@ -16,8 +16,6 @@ linters:
- testpackage
# Crashes a lot.
- gci
# Deprecated.
- exhaustivestruct
linters-settings:
lll:
line-length: 128

@ -1,4 +1,4 @@
FROM code.pztrn.name/containers/mirror/golang:1.18.3-alpine AS build
FROM golang:1.17.1-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 code.pztrn.name/containers/mirror/alpine:3.16.0
FROM alpine:latest
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 pztrn/periodicator:latest
docker run --rm -v ./config.yaml:/periodicator.yaml registry.gitlab.pztrn.name/pztrn/periodicator:latest
```
## Configuring

1
go.mod

@ -9,6 +9,7 @@ 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

@ -33,6 +33,8 @@ 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:exhaustruct
cfg := &Config{}
// nolint:exhaustivestruct
c := &Config{}
if err := yaml.Unmarshal(data, cfg); err != nil {
if err := yaml.Unmarshal(data, c); err != nil {
panic("Failed to unmarshal YAML data: " + err.Error())
}
return cfg
return c
}

@ -16,7 +16,7 @@ type Client struct {
// NewGitlabClient creates new Gitlab's client controlling structure.
func NewGitlabClient(cfg *Config) *Client {
// nolint:exhaustruct
// nolint:exhaustivestruct
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:exhaustruct
// nolint:exhaustivestruct
issues, resp, err := c.client.Issues.ListProjectIssues(projectID, &gitlab.ListProjectIssuesOptions{
ListOptions: gitlab.ListOptions{
PerPage: 1000,

@ -11,13 +11,15 @@ import (
// BaseTask is a base task structure.
type BaseTask struct {
client *gitlab.Client
projectID int
title string
body string
tags []string
executionStartTimestamp time.Time
client *gitlab.Client
title string
body string
cron string
tags []string
projectID int
dueIn time.Duration
}
@ -123,7 +125,7 @@ func (b *BaseTask) Run() {
b.log("Found no opened tasks and task should be created, doing so. Task deadline: " + nextDeadlineTS.String())
// nolint:exhaustruct
// nolint:exhaustivestruct
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 {
ExecutionStart TaskStartTime `yaml:"execution_start"`
ProjectID int `yaml:"project_id"`
Title string `yaml:"title"`
Body string `yaml:"body"`
Cron string `yaml:"cron"`
Tags []string `yaml:"tags"`
ProjectID int `yaml:"project_id"`
ExecutionStart TaskStartTime `yaml:"execution_start"`
Cron string `yaml:"cron"`
DueIn time.Duration `yaml:"due_in"`
}
@ -30,14 +30,14 @@ func (tts *TaskStartTime) UnmarshalYAML(unmarshal func(interface{}) error) error
return err
}
timeField, err := time.Parse("2006-01-02 15:04:05", timeData)
t, err := time.Parse("2006-01-02 15:04:05", timeData)
if err != nil {
// ToDo: fix it!
// nolint:wrapcheck
return err
}
tts.ts = timeField
tts.ts = t
return nil
}

@ -7,7 +7,7 @@ import (
// PrintCreationTSes prints tasks creation timestamps.
func PrintCreationTSes(client *gitlab.Client, tasks []Config) {
for _, task := range tasks {
taskData := &BaseTask{
t := &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 := taskData.getIssues()
issues, err := t.getIssues()
if err != nil {
panic("Error while getting issues from Gitlab: " + err.Error())
}
taskData.log(taskData.getNextCreationTimestamp(taskData.getLastCreationTimestamp(issues)).String())
t.log(t.getNextCreationTimestamp(t.getLastCreationTimestamp(issues)).String())
}
}
// Process processes passed tasks.
func Process(client *gitlab.Client, tasks []Config) {
for _, task := range tasks {
taskData := &BaseTask{
t := &BaseTask{
client: client,
projectID: task.ProjectID,
title: task.Title,
@ -43,6 +43,6 @@ func Process(client *gitlab.Client, tasks []Config) {
dueIn: task.DueIn,
}
taskData.Run()
t.Run()
}
}

@ -29,12 +29,12 @@ func main() {
cfg := config.Parse()
gitlabClient := gitlab.NewGitlabClient(&cfg.Gitlab)
c := gitlab.NewGitlabClient(&cfg.Gitlab)
if *showNextCreationTS {
tasks.PrintCreationTSes(gitlabClient, cfg.Tasks)
tasks.PrintCreationTSes(c, cfg.Tasks)
os.Exit(0)
}
tasks.Process(gitlabClient, cfg.Tasks)
tasks.Process(c, cfg.Tasks)
}