diff --git a/.chglog/CHANGELOG.tpl.md b/.chglog/CHANGELOG.tpl.md new file mode 100755 index 0000000..389e978 --- /dev/null +++ b/.chglog/CHANGELOG.tpl.md @@ -0,0 +1,49 @@ +{{ if .Versions -}} + +## [Unreleased] + +{{ if .Unreleased.CommitGroups -}} +{{ range .Unreleased.CommitGroups -}} +### {{ .Title }} +{{ range .Commits -}} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} +{{ end }} +{{ end -}} +{{ end -}} +{{ end -}} + +{{ range .Versions }} + +## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }} +{{ range .CommitGroups -}} +### {{ .Title }} +{{ range .Commits -}} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} +{{ end }} +{{ end -}} + +{{- if .RevertCommits -}} +### Reverts +{{ range .RevertCommits -}} +- {{ .Revert.Header }} +{{ end }} +{{ end -}} + +{{- if .NoteGroups -}} +{{ range .NoteGroups -}} +### {{ .Title }} +{{ range .Notes }} +{{ .Body }} +{{ end }} +{{ end -}} +{{ end -}} +{{ end -}} + +{{- if .Versions }} +[Unreleased]: {{ .Info.RepositoryURL }}/compare/{{ $latest := index .Versions 0 }}{{ $latest.Tag.Name }}...HEAD +{{ range .Versions -}} +{{ if .Tag.Previous -}} +[{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }} +{{ end -}} +{{ end -}} +{{ end -}} \ No newline at end of file diff --git a/.chglog/config.yml b/.chglog/config.yml new file mode 100755 index 0000000..437bb4d --- /dev/null +++ b/.chglog/config.yml @@ -0,0 +1,28 @@ +style: github +template: CHANGELOG.tpl.md +info: + title: CHANGELOG + repository_url: https://github.com/SkYNewZ/radarr-go +options: + commits: + # filters: + # Type: + # - feat + # - fix + # - perf + # - refactor + commit_groups: + # title_maps: + # feat: Features + # fix: Bug Fixes + # perf: Performance Improvements + # refactor: Code Refactoring + header: + pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$" + pattern_maps: + - Type + - Scope + - Subject + notes: + keywords: + - BREAKING CHANGE \ No newline at end of file diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..46e332f --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,104 @@ +name: Push + +on: + push: + branches-ignore: [master] + +jobs: + lint: + name: Lint code + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install golint + run: go get -u -v golang.org/x/lint/golint + + - name: Lint! + run: | + export PATH=$PATH:$(go env GOPATH)/bin + golint -set_exit_status ./... + + format: + name: Go format + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Test gogmt + run: test $(gofmt -l -e . | wc -l) -eq 0 + + - name: Print gofmt errors + if: failure() + run: gofmt -d . + + test: + name: Tests + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Execute local tests + run: go test -v -coverprofile=cover.out -cover ./... + + - name: Generate coverage report + run: go tool cover -html=cover.out -o coverage.html + + - name: Upload code coverage report + uses: actions/upload-artifact@v1 + with: + name: code-coverage-report + path: coverage.html + + install: + name: Install + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Go install + run: go install . + + install: + name: Install + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Go install + run: go install . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..99ea821 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,168 @@ +name: Release package + +on: + pull_request: + branches: [master] + push: + tags: + - "v*.*.*" + - "!v*.*.*-*" + +jobs: + lint: + name: Lint code + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install golint + run: go get -u -v golang.org/x/lint/golint + + - name: Lint! + run: | + export PATH=$PATH:$(go env GOPATH)/bin + golint -set_exit_status ./... + + format: + name: Go format + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Test gogmt + run: test $(gofmt -l -e . | wc -l) -eq 0 + + - name: Print gofmt errors + if: failure() + run: gofmt -d . + + test: + name: Tests + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Execute local tests + run: go test -v -coverprofile=cover.out -cover ./... + + - name: Generate coverage report + run: go tool cover -html=cover.out -o coverage.html + + - name: Upload code coverage report + uses: actions/upload-artifact@v1 + with: + name: code-coverage-report + path: coverage.html + + install: + name: Install + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Go install + run: go install . + + build: + name: Build + needs: + - lint + - format + - test + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup gox + run: go get github.com/mitchellh/gox + + - name: Build + run: | + REPO_ROOT=$(git rev-parse --show-toplevel) + export PATH=$PATH:$(go env GOPATH)/bin + export VERSION=$(git describe --tags --exact-match 2>/dev/null) + (cd ./cmd/radarr; gox -os="darwin linux windows" -arch="amd64" -output="$REPO_ROOT/bin/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.Version=${VERSION}") + + - name: Upload them as artifacts + uses: actions/upload-artifact@v1 + with: + name: binaries + path: bin + + release: + name: Github Release + runs-on: ubuntu-latest + needs: [build] + steps: + - name: Set up Go 1.14 + if: startsWith(github.ref, 'refs/tags/') + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + + - name: Checkout code + if: startsWith(github.ref, 'refs/tags/') + uses: actions/checkout@v2 + + - name: Get back artifacts + if: startsWith(github.ref, 'refs/tags/') + uses: actions/download-artifact@v1 + with: + name: binaries + + - name: Install git-chglog + if: startsWith(github.ref, 'refs/tags/') + run: go get -u github.com/git-chglog/git-chglog/cmd/git-chglog + + - name: Generate changelog + if: startsWith(github.ref, 'refs/tags/') + run: | + export PATH=$PATH:$(go env GOPATH)/bin + git-chglog -o CHANGELOG.md + + - name: Create a new release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: binaries/radarr* + body_path: CHANGELOG.md + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index d754b53..63a8889 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out +coverage.html # Dependency directories (remove the comment below to include it) # vendor/ diff --git a/Makefile b/Makefile deleted file mode 100644 index 0d991fa..0000000 --- a/Makefile +++ /dev/null @@ -1,80 +0,0 @@ -# Project variables -NAME := radarr -VENDOR := SkYNewZ -DESCRIPTION := Radarr Go client -MAINTAINER := Quentin Lemaire -URL := https://github.com/$(VENDOR)/$(NAME) -LICENSE := GPL-3 -PACKAGE := github.com/$(VENDOR)/$(NAME) -BINARY_DIR := cmd/radarr - -# Build variables -BUILD_DIR := bin -COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null) -VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "v0.0.0-$(COMMIT_HASH)") - -# Go variables -GOCMD := GO111MODULE=on go -GOOS ?= $(shell go env GOOS) -GOARCH ?= $(shell go env GOARCH) -GOPKGS ?= $(shell $(GOCMD) list ./... | grep -v /vendor) - -GOBUILD ?= CGO_ENABLED=0 $(GOCMD) build - -.PHONY: all -all: clean test build - -######################### -## Development targets ## -######################### -.PHONY: clean -clean: ## Clean workspace - @ $(MAKE) --no-print-directory log-$@ - rm -rf ./$(BUILD_DIR) - rm -rf ./$(NAME) - -.PHONY: test -test: ## Run tests - @ $(MAKE) --no-print-directory log-$@ - $(GOCMD) test -v $(GOPKGS) -run "Test" -coverprofile=cover.out -cover - -.PHONY: verify -verify: ## Verify 'vendor' dependencies - @ $(MAKE) --no-print-directory log-$@ - $(GOCMD) mod verify - -################### -## Build targets ## -################### -.PHONY: build -build: clean ## Build binary for current OS/ARCH - @ $(MAKE) --no-print-directory log-$@ - cd $(BINARY_DIR) && \ - $(GOBUILD) -ldflags "-X main.Version=$(VERSION)" -o ../../$(BUILD_DIR)/$(NAME) - -.PHONY: build-all -build-all: GOOS = linux darwin -build-all: GOARCH = amd64 -build-all: clean gox ## Build binary for all OS/ARCH - @ $(MAKE) --no-print-directory log-$@ - cd $(BINARY_DIR) && \ - gox -arch="$(GOARCH)" -os="$(GOOS)" -output="../../$(BUILD_DIR)/{{.Dir}}-$(VERSION)-{{.OS}}-{{.Arch}}" -ldflags "-X main.Version=$(VERSION)" - -#################### -## Helper targets ## -#################### -.PHONY: gox -gox: ## Installing gox for cross compile - @ $(MAKE) --no-print-directory log-$@ - GO111MODULE=off go get -u github.com/mitchellh/gox - -######################################################################## -## Self-Documenting Makefile Help ## -## https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html ## -######################################################################## -.PHONY: help -help: - @ grep -h -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' - -log-%: - @ grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m==> %s\033[0m\n", $$2}' diff --git a/README.md b/README.md index 30660b1..7f64d01 100644 --- a/README.md +++ b/README.md @@ -1 +1,58 @@ # Radarr Go client + +![](https://github.com/SkYNewZ/radarr/workflows/Release%20package/badge.svg) + +This is a Go package that lets you to interact with your Radarr instance. +Developed for [Radarr API v2](https://github.com/Radarr/Radarr/wiki/API). + +Radarr API v3 is under construction. See [here](https://github.com/orgs/Radarr/projects/2) and [here](https://www.reddit.com/r/radarr/comments/ejjiw2/api_v3/). + +You can use it as CLI. See [related section](cmd/radarr) + +## Supports + +Here are the currently supported endpoints: + +- [x] Calendar +- [ ] Command +- [ ] Diskspace +- [ ] History +- [ ] Movie + - [x] Returns all Movies in your collection + - [x] Returns the movie with the matching ID or 404 if no matching movie is found + - [ ] Adds a new movie to your collection + - [ ] Update an existing movie + - [ ] Delete the movie with the given ID +- [ ] Movie Lookup +- [ ] Queue +- [x] System-Status + +## Getting started + +```go +package main + +import ( + "fmt" + "log" + + "github.com/SkYNewZ/radarr" +) + +// Instanciate a standard client +func main() { + client, err := radarr.New("https://my.radarr-instance.fr", "radarr-api-key", nil) + if err != nil { + log.Fatalln(err) + } + + movie, err := client.Movies.Get(217) + if err != nil { + log.Fatalln(err) + } + fmt.Printf("%s", movie.Title) + + // Output: + // Frozen II +} +``` diff --git a/client.go b/client.go index 9c89b04..fb37930 100644 --- a/client.go +++ b/client.go @@ -1,6 +1,3 @@ -/* -Package radarr provide a Radarr https://github.com/Radarr/Radarr Go client -*/ package radarr import ( diff --git a/cmd/radarr/README.md b/cmd/radarr/README.md index 97cfd01..a823877 100644 --- a/cmd/radarr/README.md +++ b/cmd/radarr/README.md @@ -2,10 +2,18 @@ ## Getting started +### Install with Go + ```bash $ go get github.com/SkYNewZ/radarr/cmd/radarr ``` +### Download latest release + +Checkout [latest](https://github.com/SkYNewZ/radarr/releases/latest) release. Download it and place into your `$PATH`. + +## Usage + ```bash NAME: Radarr CLI - Perform actions on your Radarr instance using CLI diff --git a/cmd/radarr/go.mod b/cmd/radarr/go.mod index f3373b6..3b2fff8 100644 --- a/cmd/radarr/go.mod +++ b/cmd/radarr/go.mod @@ -3,7 +3,7 @@ module github.com/SkYNewZ/radarr/cmd/radarr go 1.14 require ( - github.com/SkYNewZ/radarr v0.0.0-20200405032438-8231759078b0 + github.com/SkYNewZ/radarr v0.0.1 github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/urfave/cli/v2 v2.2.0 ) diff --git a/cmd/radarr/go.sum b/cmd/radarr/go.sum index 22b4817..0995b01 100644 --- a/cmd/radarr/go.sum +++ b/cmd/radarr/go.sum @@ -1,6 +1,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/SkYNewZ/radarr v0.0.0-20200405032438-8231759078b0 h1:7udfcSkDJThpCzmu4XMTLA8L3U6wBSaOR6wj2T+GRXs= -github.com/SkYNewZ/radarr v0.0.0-20200405032438-8231759078b0/go.mod h1:5uS6rWJumOuN0cekKVqOpSHAw1rvkMV+/YfEChG1tSM= +github.com/SkYNewZ/radarr v0.0.1 h1:ZoGr5c10avUPRHUjGooQcWnI+jTvw2tzaPiU5T75Qso= +github.com/SkYNewZ/radarr v0.0.1/go.mod h1:5uS6rWJumOuN0cekKVqOpSHAw1rvkMV+/YfEChG1tSM= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= diff --git a/cmd/radarr/radarr.go b/cmd/radarr/main.go similarity index 100% rename from cmd/radarr/radarr.go rename to cmd/radarr/main.go diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..af14b3e --- /dev/null +++ b/doc.go @@ -0,0 +1,4 @@ +/* +Package radarr provide a Radarr https://github.com/Radarr/Radarr Go client +*/ +package radarr diff --git a/example_client_test.go b/example_client_test.go index cd01749..0e936ff 100644 --- a/example_client_test.go +++ b/example_client_test.go @@ -21,9 +21,6 @@ func ExampleNew_basic() { log.Fatalln(err) } fmt.Printf("%s", movie.Title) - - // Output: - // Frozen II } // Instanciate a client with a custom HTTP client @@ -40,7 +37,4 @@ func ExampleNew_advanced() { log.Fatalln(err) } fmt.Printf("%s", movie.Title) - - // Output: - // Frozen II }