Skip to content

Commit

Permalink
chore: add pre-commit for sorting go imports
Browse files Browse the repository at this point in the history
  • Loading branch information
syhily committed Nov 9, 2022
1 parent 7a14aac commit a5b98b0
Show file tree
Hide file tree
Showing 29 changed files with 150 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ linters-settings:
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/bibliolater/bookhunter
local-prefixes: github.com/bookstairs/bookhunter
lll:
line-length: 140
misspell:
Expand Down
20 changes: 10 additions & 10 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ builds:
- id: bookhunter
ldflags:
- -s -w
- -X github.com/bibliolater/bookhunter/cmd.gitMajor={{ .Major }}
- -X github.com/bibliolater/bookhunter/cmd.gitMinor={{ .Minor }}
- -X github.com/bibliolater/bookhunter/cmd.gitVersion={{ .Version }}
- -X github.com/bibliolater/bookhunter/cmd.gitCommit={{ .Commit }}
- -X github.com/bibliolater/bookhunter/cmd.gitTreeState=clean
- -X github.com/bibliolater/bookhunter/cmd.buildDate={{ .Date }}
- -X github.com/bookstairs/bookhunter/cmd.gitMajor={{ .Major }}
- -X github.com/bookstairs/bookhunter/cmd.gitMinor={{ .Minor }}
- -X github.com/bookstairs/bookhunter/cmd.gitVersion={{ .Version }}
- -X github.com/bookstairs/bookhunter/cmd.gitCommit={{ .Commit }}
- -X github.com/bookstairs/bookhunter/cmd.gitTreeState=clean
- -X github.com/bookstairs/bookhunter/cmd.buildDate={{ .Date }}
env:
- CGO_ENABLED=0
goos:
Expand All @@ -27,27 +27,27 @@ builds:

scoop:
bucket:
owner: bibliolater
owner: bookstairs
name: scoop-bucket
branch: master
commit_author:
name: syhily
email: syhily@gmail.com
homepage: "https://github.com/bibliolater"
homepage: "https://github.com/bookstairs"
description: "Software to download chinese ebooks from Internet."
license: MIT

brews:
- name: bookhunter
tap:
owner: bibliolater
owner: bookstairs
name: homebrew-tap
branch: master
commit_author:
name: syhily
email: syhily@gmail.com
folder: Formula
homepage: "https://github.com/bibliolater"
homepage: "https://github.com/bookstairs"
description: "Software to download chinese ebooks from Internet."
license: "MIT"
install: |
Expand Down
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- repo: local
hooks:
- id: goimports
name: goimports
entry: goimports.sh
language: script
types: [ go ]
pass_filenames: true
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-beta.5
hooks:
- id: go-mod-tidy-repo
- id: golangci-lint-mod
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 bibliolater
Copyright (c) 2022 bookstairs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is totally rewrite fork compare to its [original version](https://github.co

1. [Go Releaser](https://github.com/goreleaser/goreleaser) is used for releasing and local building
2. [golangci-lint](https://github.com/golangci/golangci-lint) is used for code style.
3. [goimports-reviser](https://github.com/incu6us/goimports-reviser) is used for sorting imports.
3. [pre-commit](https://pre-commit.com/) is used for checking code before committing.

## Feature

Expand Down Expand Up @@ -102,20 +102,20 @@ TODO
### Homebrew (for macOS, Linux)
```shell
brew tap bibliolater/tap
brew tap bookstairs/tap
brew install bookhunter
```
### Scope (for Windows)
```shell
scoop bucket add bibliolater https://github.com/bibliolater/scoop-bucket.git
scoop install bibliolater/bookhunter
scoop bucket add bookstairs https://github.com/bookstairs/scoop-bucket.git
scoop install bookstairs/bookhunter
```
### Manually
Download the latest release in [release page](https://github.com/bibliolater/bookhunter/releases). Choose related
Download the latest release in [release page](https://github.com/bookstairs/bookhunter/releases). Choose related
tarball by your running environment.
## Usage
Expand Down
6 changes: 3 additions & 3 deletions cmd/sanqiu.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"

"github.com/bibliolater/bookhunter/pkg/log"
"github.com/bibliolater/bookhunter/pkg/spider"
"github.com/bibliolater/bookhunter/sanqiu"
"github.com/bookstairs/bookhunter/pkg/log"
"github.com/bookstairs/bookhunter/pkg/spider"
"github.com/bookstairs/bookhunter/sanqiu"
)

const lowestBookID = 163
Expand Down
2 changes: 1 addition & 1 deletion cmd/talebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"github.com/spf13/cobra"

"github.com/bibliolater/bookhunter/cmd/talebook"
"github.com/bookstairs/bookhunter/cmd/talebook"
)

// talebookCmd used to download books from talebook
Expand Down
6 changes: 3 additions & 3 deletions cmd/talebook/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"

"github.com/bibliolater/bookhunter/pkg/log"
"github.com/bibliolater/bookhunter/pkg/spider"
"github.com/bibliolater/bookhunter/talebook"
"github.com/bookstairs/bookhunter/pkg/log"
"github.com/bookstairs/bookhunter/pkg/spider"
"github.com/bookstairs/bookhunter/talebook"
)

// Used for downloading books from talebook website.
Expand Down
6 changes: 3 additions & 3 deletions cmd/talebook/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"

"github.com/bibliolater/bookhunter/pkg/log"
"github.com/bibliolater/bookhunter/pkg/spider"
"github.com/bibliolater/bookhunter/talebook"
"github.com/bookstairs/bookhunter/pkg/log"
"github.com/bookstairs/bookhunter/pkg/spider"
"github.com/bookstairs/bookhunter/talebook"
)

// Used for register account on talebook website.
Expand Down
6 changes: 3 additions & 3 deletions cmd/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"

"github.com/bibliolater/bookhunter/pkg/log"
"github.com/bibliolater/bookhunter/pkg/spider"
"github.com/bibliolater/bookhunter/telegram"
"github.com/bookstairs/bookhunter/pkg/log"
"github.com/bookstairs/bookhunter/pkg/spider"
"github.com/bookstairs/bookhunter/telegram"
)

// Used for downloading books from telegram channel .
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/spf13/cobra"

"github.com/bibliolater/bookhunter/pkg/log"
"github.com/bookstairs/bookhunter/pkg/log"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/bibliolater/bookhunter
module github.com/bookstairs/bookhunter

go 1.18

Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ github.com/gotd/ige v0.2.2 h1:XQ9dJZwBfDnOGSTxKXBGP4gMud3Qku2ekScRjDWWfEk=
github.com/gotd/ige v0.2.2/go.mod h1:tuCRb+Y5Y3eNTo3ypIfNpQ4MFjrnONiL2jN2AKZXmb0=
github.com/gotd/neo v0.1.5 h1:oj0iQfMbGClP8xI59x7fE/uHoTJD7NZH9oV1WNuPukQ=
github.com/gotd/neo v0.1.5/go.mod h1:9A2a4bn9zL6FADufBdt7tZt+WMhvZoc5gWXihOPoiBQ=
github.com/gotd/td v0.56.0 h1:SlpVIxKbEhNzQ83lbkbBB0uS1QONCP+K1EE0YQOAHJU=
github.com/gotd/td v0.56.0/go.mod h1:wILjug50hgK8UkPwGcYRGQ6+7TYX5Uuf2yU873umgvM=
github.com/gotd/td v0.57.0 h1:33DHkkfoJSeT94PM3bfPI3gr2D4Nv/KoQwIZBFOG9uc=
github.com/gotd/td v0.57.0/go.mod h1:CPyg0p4VJM8GeVHD2zBX905G7auYfNZeHdR+anvS4mQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
Expand Down Expand Up @@ -134,8 +132,6 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 h1:bRb386wvrE+oBNdF1d/Xh9mQrfQ4ecYhW5qJ5GvTGT4=
golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -153,8 +149,6 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -166,8 +160,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba h1:O8mE0/t419eoIwhTFpKVkHiTs/Igowgfkj25AcZrtiE=
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20220411224347-583f2d630306 h1:+gHMid33q6pen7kv9xvT+JRinntgeXO2AeZVd0AWD3w=
golang.org/x/time v0.0.0-20220411224347-583f2d630306/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
70 changes: 70 additions & 0 deletions goimports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

##
# parse_file_hook_args
# Creates global vars:
# OPTIONS: List of options to passed to command
# FILES : List of files to process, filtered against ignore_file_pattern_array
#
function parse_file_hook_args {
OPTIONS=()
# If arg doesn't pass [ -f ] check, then it is assumed to be an option
#
while [ $# -gt 0 ] && [ "$1" != "--" ] && [ ! -f "$1" ]; do
OPTIONS+=("$1")
shift
done

local all_files
all_files=()
# Assume start of file list (may still be options)
#
while [ $# -gt 0 ] && [ "$1" != "--" ]; do
all_files+=("$1")
shift
done

# If '--' next, then files = options
#
if [ "$1" == "--" ]; then
shift
# Append to previous options
#
OPTIONS+=("${all_files[@]}")
all_files=()
fi

# Any remaining arguments are assumed to be files
#
all_files+=("$@")

# Filter out vendor entries and ignore_file_pattern_array
#
FILES=()
local file pattern
ignore_file_pattern_array+=( "vendor/*" "*/vendor/*" "*/vendor" )
for file in "${all_files[@]}"; do
for pattern in "${ignore_file_pattern_array[@]}"; do
if [[ "${file}" == ${pattern} ]] ; then # pattern => unquoted
continue 2
fi
done
FILES+=("${file}")
done
}

parse_file_hook_args "$@"

##
# Remove all blank lines in go 'imports' statements, then sort with default goimports.
# This scripts only works in macOS with `brew install gnu-sed`
# Change gsed to sed in case of you are developing under the Linux.
#
for file in "${FILES[@]}"; do
gsed -i '
/^import/,/)/ {
/^$/ d
}
' "${file}"
goimports -l -d -local github.com/bookstairs/bookhunter -w "${file}"
done
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/bibliolater/bookhunter/cmd"
"github.com/bookstairs/bookhunter/cmd"
)

// main the entrypoint for the downloader.
Expand Down
2 changes: 1 addition & 1 deletion pkg/spider/aliyundrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/go-resty/resty/v2"

"github.com/bibliolater/bookhunter/pkg/spider/aliyundrive"
"github.com/bookstairs/bookhunter/pkg/spider/aliyundrive"
)

type AliYunConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/spider/aliyundrive/share.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aliyundrive

import (
"github.com/bibliolater/bookhunter/pkg/log"
"github.com/bookstairs/bookhunter/pkg/log"
)

func (ali AliYunDrive) GetAnonymousShare(shareId string) (*GetShareInfoResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/spider/aliyundrive/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"

"github.com/bibliolater/bookhunter/pkg/log"
"github.com/bookstairs/bookhunter/pkg/log"
)

func (ali AliYunDrive) GetAuthorizationToken() string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/spider/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path"
"strings"

"github.com/bibliolater/bookhunter/pkg/log"
"github.com/bookstairs/bookhunter/pkg/log"
)

type Client struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/spider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/spf13/cobra"

"github.com/bibliolater/bookhunter/pkg/log"
"github.com/bookstairs/bookhunter/pkg/log"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/spider/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"
"sync"

"github.com/bibliolater/bookhunter/pkg/log"
"github.com/bookstairs/bookhunter/pkg/log"
)

type jar struct {
Expand Down
4 changes: 2 additions & 2 deletions sanqiu/bookmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/PuerkitoBio/goquery"

"github.com/bibliolater/bookhunter/pkg/log"
"github.com/bibliolater/bookhunter/pkg/spider"
"github.com/bookstairs/bookhunter/pkg/log"
"github.com/bookstairs/bookhunter/pkg/spider"
)

type LinkType string
Expand Down
8 changes: 4 additions & 4 deletions sanqiu/sanqiu.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (

"github.com/PuerkitoBio/goquery"

"github.com/bibliolater/bookhunter/pkg/log"
"github.com/bibliolater/bookhunter/pkg/progress"
"github.com/bibliolater/bookhunter/pkg/rename"
"github.com/bibliolater/bookhunter/pkg/spider"
"github.com/bookstairs/bookhunter/pkg/log"
"github.com/bookstairs/bookhunter/pkg/progress"
"github.com/bookstairs/bookhunter/pkg/rename"
"github.com/bookstairs/bookhunter/pkg/spider"
)

// DefaultWebsite is the website for sanqiu book.
Expand Down

0 comments on commit a5b98b0

Please sign in to comment.