[Add] VersionCheck #215

Merged
lafriks merged 12 commits from 6543/go-sdk:version-check into master 2020-01-27 06:20:55 +00:00
Owner

add function to check gitea versions

use versionCheck for new introduced APIs of gitea_v1.11.0

close #197

add function to check gitea versions use versionCheck for new introduced APIs of gitea_v1.11.0 close #197
6543 added the
kind/feature
kind/proposal
labels 2020-01-06 19:18:25 +00:00
6543 changed title from version-check to [Add] VersionCheck 2020-01-06 19:18:40 +00:00
zeripath reviewed 2020-01-06 19:44:05 +00:00
Dismissed
gitea/client.go Outdated
@ -19,3 +22,3 @@
// Version return the library version
func Version() string {
return "0.12.3"
return "0.11.0"
Owner

I don't think we can really reduce the version of the library - I see what you're trying to do though - maybe we should just make it 1.11.0?

I don't think we can really reduce the version of the library - I see what you're trying to do though - maybe we should just make it 1.11.0?
Author
Owner

I dont like to go out of 0.x jet :https://medium.com/@aman.sardana/go-modules-versioning-dependency-management-d5f96b490774

"...version 0 is an exception for backward compatibility rule of golang as the version updated before version 1 can be backward incompatible. It is best for the libraries that are just starting. ..."

at this point we still can remove stuff ...
if we are sure that we stay in this structure we can go on to 1.x

I dont like to go out of 0.x jet :https://medium.com/@aman.sardana/go-modules-versioning-dependency-management-d5f96b490774 "...version 0 is an exception for backward compatibility rule of golang as the version updated before version 1 can be backward incompatible. It is best for the libraries that are just starting. ..." at this point we still can remove stuff ... if we are sure that we stay in this structure we can go on to 1.x
Owner

I'd probably argue that we don't need to vendor any more - but I guess it depends on our lowest supported version of golang.

I'd probably argue that we don't need to vendor any more - but I guess it depends on our lowest supported version of golang.
Author
Owner

@zeripath

I dont like to go out of 0.x jet :https://medium.com/@aman.sardana/go-modules-versioning-dependency-management-d5f96b490774

“…version 0 is an exception for backward compatibility rule of golang as the version updated before version 1 can be backward incompatible. It is best for the libraries that are just starting. …”

at this point we still can remove stuff … if we are sure that we stay in this structure we can go on to 1.x

@zeripath I dont like to go out of 0.x jet :https://medium.com/@aman.sardana/go-modules-versioning-dependency-management-d5f96b490774 “…version 0 is an exception for backward compatibility rule of golang as the version updated before version 1 can be backward incompatible. It is best for the libraries that are just starting. …” at this point we still can remove stuff … if we are sure that we stay in this structure we can go on to 1.x
Owner

@6543 I will agree with @zeripath that we don't need vendor the dependencies on this library project.

@6543 I will agree with @zeripath that we don't need vendor the dependencies on this library project.
6543 changed title from [Add] VersionCheck to [WIP] [Add] VersionCheck 2020-01-07 11:12:29 +00:00
lafriks approved these changes 2020-01-08 20:16:54 +00:00
Dismissed
lafriks left a comment
Member

For performance reasons it would be better to request server version only once in NewClient

For performance reasons it would be better to request server version only once in `NewClient`
gitea/version.go Outdated
@ -0,0 +9,4 @@
"github.com/hashicorp/go-version"
)
var serverVersion *version.Version
Member

This should be moved into Client struct as field serverVersion string

This should be moved into `Client` struct as field `serverVersion string`
gitea/version.go Outdated
@ -0,0 +12,4 @@
var serverVersion *version.Version
// ServerVersion returns the version of the server
func (c *Client) ServerVersion() (string, error) {
Member
func (c *Client) ServerVersion() (string, error) {
	if len(c.serverVersion) != 0 {
		return c.serverVersion, nil
	}
	if err := c.ReloadServerVersion(); err != nil {
		return "", err
	}
	return c.serverVersion, nil
}

func (c *Client) ReloadServerVersion() error {
	// Reset cached server version string
	c.serverVersion = ""
	var v = struct {
		Version string `json:"version"`
	}{}
	if err := c.getParsedResponse("GET", "/version", nil, nil, &v) != nil {
		return err
	}
	c.serverVersion = v.Version
	return nil
}
```go func (c *Client) ServerVersion() (string, error) { if len(c.serverVersion) != 0 { return c.serverVersion, nil } if err := c.ReloadServerVersion(); err != nil { return "", err } return c.serverVersion, nil } func (c *Client) ReloadServerVersion() error { // Reset cached server version string c.serverVersion = "" var v = struct { Version string `json:"version"` }{} if err := c.getParsedResponse("GET", "/version", nil, nil, &v) != nil { return err } c.serverVersion = v.Version return nil } ```
lafriks reviewed 2020-01-08 20:25:37 +00:00
Dismissed
gitea/client.go Outdated
@ -36,3 +39,4 @@
accessToken: token,
client: &http.Client{},
}
if raw, err := c.ServerVersion(); err == nil {
Member

Not needed here, load server version only when needed

Not needed here, load server version only when needed
lafriks requested changes 2020-01-08 20:26:29 +00:00
Dismissed
gitea/client.go Outdated
@ -25,3 +27,4 @@
// Client represents a Gitea API client.
type Client struct {
url string
accessToken string
Member
	serverVersion string
```go serverVersion string ```
6543 changed title from [WIP] [Add] VersionCheck to [Add] VersionCheck 2020-01-24 23:08:34 +00:00
Author
Owner

@lafriks can you review again?

@lafriks can you review again?
6543 added this to the v0.11.0 milestone 2020-01-25 00:41:20 +00:00
lunny requested changes 2020-01-25 02:25:41 +00:00
Dismissed
gitea/version.go Outdated
@ -0,0 +20,4 @@
// CheckServerVersionConstraint validates that the login's server satisfies a
// given version constraint such as ">= 1.11.0+dev"
func (c *Client) CheckServerVersionConstraint(constraint string) error {
Owner

I think you should have a lock since there maybe multiple goroutines check the verions.

I think you should have a lock since there maybe multiple goroutines check the verions.
Author
Owner

@lunny hope 9e722bb47272557c4aceb361dee8a4247743f8f1 is wat you want ...

@lunny hope 9e722bb47272557c4aceb361dee8a4247743f8f1 is wat you want ...
Owner

Please resolve conflicts.

Please resolve conflicts.
Author
Owner

done

done
Author
Owner

@lafriks are you ok as it is now?

@lafriks are you ok as it is now?
lafriks reviewed 2020-01-26 18:19:00 +00:00
Dismissed
gitea/version.go Outdated
@ -0,0 +22,4 @@
// given version constraint such as ">= 1.11.0+dev"
func (c *Client) CheckServerVersionConstraint(constraint string) (err error) {
setV := func() {
raw, _ := c.ServerVersion()
Member

What if there is error?

What if there is error?
Author
Owner

raw = "" -> CheckServerVersionConstraint will always end with return fmt.Errorf("gitea se...

raw = "" -> CheckServerVersionConstraint will always end with `return fmt.Errorf("gitea se...`
Member

You can use sync.RWMutex instead to be able to control behavior with errors better

You can use sync.RWMutex instead to be able to control behavior with errors better
Author
Owner

@lafriks lunny like to prevent a race condition when somebody is doing this:

go client.GetIssueCommentReactions()
client.GetIssueCommentReactions()

and so I used sync.Once ...

@lafriks lunny like to prevent a race condition when somebody is doing this: ```go go client.GetIssueCommentReactions() client.GetIssueCommentReactions() ``` and so I used sync.Once ...
Author
Owner

@lafriks sync.RWMutex is nice!

@lafriks **sync.RWMutex** is nice!
Author
Owner

I name it neutral so it client.propertyLock can be used for altering any type of property

EDIT: outdated

I name it neutral so it **client.propertyLock** can be used for altering any type of property EDIT: outdated
lafriks approved these changes 2020-01-26 22:17:45 +00:00
Dismissed
lafriks approved these changes 2020-01-26 22:21:16 +00:00
Dismissed
6543 removed the
kind/proposal
label 2020-01-26 22:50:13 +00:00
lunny reviewed 2020-01-27 04:13:47 +00:00
Dismissed
gitea/version.go Outdated
Owner

Why not cache the version here?

Why not cache the version here?
Owner

I think we should also enable -race flag on go test.
And a goroutine test is better.

I think we should also enable `-race` flag on `go test`. And a goroutine test is better.
Author
Owner

@lunny enabled race

@lunny enabled race
lunny approved these changes 2020-01-27 05:09:14 +00:00
Dismissed
Author
Owner

Ready to merge :)

Ready to merge :)
lafriks approved these changes 2020-01-27 06:18:35 +00:00
Dismissed
lafriks referenced this issue from a commit 2020-01-27 06:20:53 +00:00
[Add] VersionCheck (#215) enable race test make go-vet happy code format secound Func RWMutex fix prevent race condition add TEST cleanup make go-version work without vendoring dont change library version use Server Version Check on NewClient save serverVersion Makefile: export test env var (#234) exporte test var to env on test target Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/234 Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: John Olheiser <john.olheiser@gmail.com> use golangci-lint and revive for linting (match main repo) (#220) Co-authored-by: 6543 <6543@noreply.gitea.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: John Olheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/220 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: John Olheiser <john.olheiser@gmail.com> [Makefile] Add "test-instance"; Add "help" (#231) PASSWORD_COMPLEXITY = off fix test Makefile: add "test-instance" (start a gitea instance for test) and add a help menue Fix ListIssue Functions (now respect ListIssueOption's) (#225) fix test add Test add more test cases and fix nice log add Issue Tests impruve more Repo Tests and mv createTestRepo introduce "createTestRepo" a standad func to create a repo for testing add workaround * Update Dates * Fix ListIssueOption Fix ListRepoPullRequests (#219) add ToDo notice add ListRepoPullRequests TEST remove useless drone config emtrys fmt ping CI add new Options from PR #217 use query params Add some PR list options (#217) Empty Commit Add enums Add some PR list options Add test framework (#227) [Extend] StopWatch struct & functions (#211) add StopWatch struct & functions [Add] reaction struct and functions (#213) add struct and functions Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io> [Add] issue Un-/Subscription function (#214) fix lint add issue subscription function Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io> [Add] GetBlob (#212) fix header from PR 206 add GetBlob Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: 6543 <6543@noreply.gitea.io> Add test framework (#227) Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: John Olheiser <john.olheiser@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Add some PR list options (#217) Empty Commit Add enums Add some PR list options Add test framework (#227) [Extend] StopWatch struct & functions (#211) add StopWatch struct & functions [Add] reaction struct and functions (#213) add struct and functions Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io> [Add] issue Un-/Subscription function (#214) fix lint add issue subscription function Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io> [Add] GetBlob (#212) fix header from PR 206 add GetBlob Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: 6543 <6543@noreply.gitea.io> Add test framework (#227) Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: John Olheiser <john.olheiser@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/225 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/231 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: John Olheiser <john.olheiser@gmail.com> Fix ListIssue Functions (now respect ListIssueOption's) (#225) fix test add Test add more test cases and fix nice log add Issue Tests impruve more Repo Tests and mv createTestRepo introduce "createTestRepo" a standad func to create a repo for testing add workaround * Update Dates * Fix ListIssu... Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: John Olheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/215 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: lafriks <lafriks@noreply.gitea.io>
lafriks closed this pull request 2020-01-27 06:20:55 +00:00
lafriks deleted branch version-check 2020-01-27 06:21:10 +00:00
Sign in to join this conversation.
No description provided.