Set client version to lowest for compat if server version can't be recognized #612
|
@ -9,6 +9,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -67,6 +68,9 @@ func NewClient(url string, options ...ClientOption) (*Client, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := client.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
if err := client.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
||||||
|
if errors.As(err, &ErrUnknownVersion{}) {
|
||||||
|
return client, err
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ package gitea
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/go-version"
|
"github.com/hashicorp/go-version"
|
||||||
)
|
)
|
||||||
|
@ -70,6 +71,16 @@ var (
|
||||||
version1_17_0 = version.Must(version.NewVersion("1.17.0"))
|
version1_17_0 = version.Must(version.NewVersion("1.17.0"))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrUnknownVersion is an unknown version from the API
|
||||||
|
type ErrUnknownVersion struct {
|
||||||
|
raw string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error fulfills error
|
||||||
|
func (e ErrUnknownVersion) Error() string {
|
||||||
|
return fmt.Sprintf("unknown version: %s", e.raw)
|
||||||
|
}
|
||||||
|
|
||||||
// checkServerVersionGreaterThanOrEqual is the canonical way in the SDK to check for versions for API compatibility reasons
|
// checkServerVersionGreaterThanOrEqual is the canonical way in the SDK to check for versions for API compatibility reasons
|
||||||
func (c *Client) checkServerVersionGreaterThanOrEqual(v *version.Version) error {
|
func (c *Client) checkServerVersionGreaterThanOrEqual(v *version.Version) error {
|
||||||
if c.ignoreVersion {
|
if c.ignoreVersion {
|
||||||
|
@ -97,6 +108,11 @@ func (c *Client) loadServerVersion() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if c.serverVersion, err = version.NewVersion(raw); err != nil {
|
if c.serverVersion, err = version.NewVersion(raw); err != nil {
|
||||||
|
if strings.TrimSpace(raw) != "" {
|
||||||
|
// Version was something, just not recognized
|
||||||
|
c.serverVersion = version1_11_0
|
||||||
|
err = ErrUnknownVersion{raw: raw}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user