generated from LinuxSuRen/github-go
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to parse URL from hd-home (#10)
* Add support to parse URL from hd-home * Parse binary field * Test pass with install kind and kubekey * Fix the errors found by gosec * Typo fixes found by typoci
- Loading branch information
1 parent
d81be53
commit 7a27747
Showing
7 changed files
with
226 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
dictionaries: | ||
- en | ||
- en_GB | ||
exclude_fiels: | ||
- ".github/**/*" | ||
- "go.mod" | ||
- "go.sum" | ||
- Makefile | ||
excluded_words: | ||
- KubeSphere | ||
- kubespheredev | ||
- minio | ||
- jcli | ||
- ioutil | ||
- Unmarshal | ||
- Errorf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package pkg | ||
|
||
import ( | ||
"context" | ||
"github.com/google/go-github/v29/github" | ||
) | ||
|
||
// ReleaseClient is the client of jcli github | ||
type ReleaseClient struct { | ||
Client *github.Client | ||
Org string | ||
Repo string | ||
} | ||
|
||
// ReleaseAsset is the asset from GitHub release | ||
type ReleaseAsset struct { | ||
TagName string | ||
Body string | ||
} | ||
|
||
// Init init the GitHub client | ||
func (g *ReleaseClient) Init() { | ||
g.Client = github.NewClient(nil) | ||
} | ||
|
||
// GetLatestJCLIAsset returns the latest jcli asset | ||
func (g *ReleaseClient) GetLatestJCLIAsset() (*ReleaseAsset, error) { | ||
return g.GetLatestReleaseAsset(g.Org, g.Repo) | ||
} | ||
|
||
// GetLatestReleaseAsset returns the latest release asset | ||
func (g *ReleaseClient) GetLatestReleaseAsset(owner, repo string) (ra *ReleaseAsset, err error) { | ||
ctx := context.Background() | ||
|
||
var release *github.RepositoryRelease | ||
if release, _, err = g.Client.Repositories.GetLatestRelease(ctx, owner, repo); err == nil { | ||
ra = &ReleaseAsset{ | ||
TagName: release.GetTagName(), | ||
Body: release.GetBody(), | ||
} | ||
} | ||
return | ||
} | ||
|
||
// GetJCLIAsset returns the asset from a tag name | ||
func (g *ReleaseClient) GetJCLIAsset(tagName string) (*ReleaseAsset, error) { | ||
return g.GetReleaseAssetByTagName(g.Org, g.Repo, tagName) | ||
} | ||
|
||
// GetReleaseAssetByTagName returns the release asset by tag name | ||
func (g *ReleaseClient) GetReleaseAssetByTagName(owner, repo, tagName string) (ra *ReleaseAsset, err error) { | ||
ctx := context.Background() | ||
|
||
opt := &github.ListOptions{ | ||
PerPage: 99999, | ||
} | ||
|
||
var releaseList []*github.RepositoryRelease | ||
if releaseList, _, err = g.Client.Repositories.ListReleases(ctx, owner, repo, opt); err == nil { | ||
for _, item := range releaseList { | ||
if item.GetTagName() == tagName { | ||
ra = &ReleaseAsset{ | ||
TagName: item.GetTagName(), | ||
Body: item.GetBody(), | ||
} | ||
break | ||
} | ||
} | ||
} | ||
return | ||
} |