From 88e041b278f7d047f6d7e7395528562123e59c3d Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 13 Mar 2024 18:26:19 +0900 Subject: [PATCH 1/3] gitea-packages-update-check: first commit --- gitea-packages-update-check/go.mod | 1 + gitea-packages-update-check/main.go | 72 ++++++++++++ gitea-packages-update-check/packages.go | 145 ++++++++++++++++++++++++ 3 files changed, 218 insertions(+) create mode 100644 gitea-packages-update-check/go.mod create mode 100644 gitea-packages-update-check/main.go create mode 100644 gitea-packages-update-check/packages.go diff --git a/gitea-packages-update-check/go.mod b/gitea-packages-update-check/go.mod new file mode 100644 index 0000000..4927cc3 --- /dev/null +++ b/gitea-packages-update-check/go.mod @@ -0,0 +1 @@ +module gitea-packages-update-ceck diff --git a/gitea-packages-update-check/main.go b/gitea-packages-update-check/main.go new file mode 100644 index 0000000..5107404 --- /dev/null +++ b/gitea-packages-update-check/main.go @@ -0,0 +1,72 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "io" + "log" + "net/http" + "os" + "time" +) + +func main() { + var ( + r = flag.String("registry", "git.usbharu.dev", "gitea registry") + s = flag.Bool("https", true, "use https") + o = flag.String("owner", "usbharu", "package owner") + n = flag.String("name", "", "package name") + t = flag.String("type", "generic", "package type") + ) + + flag.Parse() + + var protocol string + if *s { + protocol = "https" + } else { + protocol = "http" + } + + url := protocol + "://" + *r + "/api/v1/packages/" + *o + "?type=" + *t + "&q=" + *n + "&token=" + os.Getenv("GITEA_TOKEN") + + get, err := http.Get(url) + if err != nil { + log.Fatal(err) + return + } + if get.StatusCode != 200 { + log.Fatalf("The Status is not 200. %d", get.StatusCode) + } + + defer func(Body io.ReadCloser) { + err := Body.Close() + if err != nil { + log.Fatal(err) + } + }(get.Body) + + all, err := io.ReadAll(get.Body) + if err != nil { + log.Fatal(err) + return + } + + var p []Packages + if err := json.Unmarshal(all, &p); err != nil { + log.Fatal("Error in json decode", err) + return + } + + last := time.Time{} + var packageT Packages + for _, packages := range p { + if last.Before(packages.CreatedAt) { + last = packages.CreatedAt + packageT = packages + } + } + + fmt.Printf("%s://%s/api/v1/packages/%s/%s/%s/%s", protocol, *r, *o, *t, packageT.Name, packageT.Version) +} diff --git a/gitea-packages-update-check/packages.go b/gitea-packages-update-check/packages.go new file mode 100644 index 0000000..7811bc8 --- /dev/null +++ b/gitea-packages-update-check/packages.go @@ -0,0 +1,145 @@ +package main + +import "time" + +type Packages struct { + Id int `json:"id"` + Owner struct { + Id int `json:"id"` + Login string `json:"login"` + LoginName string `json:"login_name"` + FullName string `json:"full_name"` + Email string `json:"email"` + AvatarUrl string `json:"avatar_url"` + Language string `json:"language"` + IsAdmin bool `json:"is_admin"` + LastLogin time.Time `json:"last_login"` + Created time.Time `json:"created"` + Restricted bool `json:"restricted"` + Active bool `json:"active"` + ProhibitLogin bool `json:"prohibit_login"` + Location string `json:"location"` + Website string `json:"website"` + Description string `json:"description"` + Visibility string `json:"visibility"` + FollowersCount int `json:"followers_count"` + FollowingCount int `json:"following_count"` + StarredReposCount int `json:"starred_repos_count"` + Username string `json:"username"` + } `json:"owner"` + Repository struct { + Id int `json:"id"` + Owner struct { + Id int `json:"id"` + Login string `json:"login"` + LoginName string `json:"login_name"` + FullName string `json:"full_name"` + Email string `json:"email"` + AvatarUrl string `json:"avatar_url"` + Language string `json:"language"` + IsAdmin bool `json:"is_admin"` + LastLogin time.Time `json:"last_login"` + Created time.Time `json:"created"` + Restricted bool `json:"restricted"` + Active bool `json:"active"` + ProhibitLogin bool `json:"prohibit_login"` + Location string `json:"location"` + Website string `json:"website"` + Description string `json:"description"` + Visibility string `json:"visibility"` + FollowersCount int `json:"followers_count"` + FollowingCount int `json:"following_count"` + StarredReposCount int `json:"starred_repos_count"` + Username string `json:"username"` + } `json:"owner"` + Name string `json:"name"` + FullName string `json:"full_name"` + Description string `json:"description"` + Empty bool `json:"empty"` + Private bool `json:"private"` + Fork bool `json:"fork"` + Template bool `json:"template"` + Parent interface{} `json:"parent"` + Mirror bool `json:"mirror"` + Size int `json:"size"` + Language string `json:"language"` + LanguagesUrl string `json:"languages_url"` + HtmlUrl string `json:"html_url"` + Url string `json:"url"` + Link string `json:"link"` + SshUrl string `json:"ssh_url"` + CloneUrl string `json:"clone_url"` + OriginalUrl string `json:"original_url"` + Website string `json:"website"` + StarsCount int `json:"stars_count"` + ForksCount int `json:"forks_count"` + WatchersCount int `json:"watchers_count"` + OpenIssuesCount int `json:"open_issues_count"` + OpenPrCounter int `json:"open_pr_counter"` + ReleaseCounter int `json:"release_counter"` + DefaultBranch string `json:"default_branch"` + Archived bool `json:"archived"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + ArchivedAt time.Time `json:"archived_at"` + Permissions struct { + Admin bool `json:"admin"` + Push bool `json:"push"` + Pull bool `json:"pull"` + } `json:"permissions"` + HasIssues bool `json:"has_issues"` + InternalTracker struct { + EnableTimeTracker bool `json:"enable_time_tracker"` + AllowOnlyContributorsToTrackTime bool `json:"allow_only_contributors_to_track_time"` + EnableIssueDependencies bool `json:"enable_issue_dependencies"` + } `json:"internal_tracker"` + HasWiki bool `json:"has_wiki"` + HasPullRequests bool `json:"has_pull_requests"` + HasProjects bool `json:"has_projects"` + HasReleases bool `json:"has_releases"` + HasPackages bool `json:"has_packages"` + HasActions bool `json:"has_actions"` + IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"` + AllowMergeCommits bool `json:"allow_merge_commits"` + AllowRebase bool `json:"allow_rebase"` + AllowRebaseExplicit bool `json:"allow_rebase_explicit"` + AllowSquashMerge bool `json:"allow_squash_merge"` + AllowRebaseUpdate bool `json:"allow_rebase_update"` + DefaultDeleteBranchAfterMerge bool `json:"default_delete_branch_after_merge"` + DefaultMergeStyle string `json:"default_merge_style"` + DefaultAllowMaintainerEdit bool `json:"default_allow_maintainer_edit"` + AvatarUrl string `json:"avatar_url"` + Internal bool `json:"internal"` + MirrorInterval string `json:"mirror_interval"` + MirrorUpdated time.Time `json:"mirror_updated"` + RepoTransfer interface{} `json:"repo_transfer"` + } `json:"repository"` + Creator struct { + Id int `json:"id"` + Login string `json:"login"` + LoginName string `json:"login_name"` + FullName string `json:"full_name"` + Email string `json:"email"` + AvatarUrl string `json:"avatar_url"` + Language string `json:"language"` + IsAdmin bool `json:"is_admin"` + LastLogin time.Time `json:"last_login"` + Created time.Time `json:"created"` + Restricted bool `json:"restricted"` + Active bool `json:"active"` + ProhibitLogin bool `json:"prohibit_login"` + Location string `json:"location"` + Website string `json:"website"` + Description string `json:"description"` + Visibility string `json:"visibility"` + FollowersCount int `json:"followers_count"` + FollowingCount int `json:"following_count"` + StarredReposCount int `json:"starred_repos_count"` + Username string `json:"username"` + } `json:"creator"` + Type string `json:"type"` + Name string `json:"name"` + Version string `json:"version"` + HtmlUrl string `json:"html_url"` + CreatedAt time.Time `json:"created_at"` +} From 74bba0f2623c3d64c06f445c99fb14e175a05810 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 13 Mar 2024 18:32:29 +0900 Subject: [PATCH 2/3] =?UTF-8?q?gitea-packages-update-check:=20ci=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitea-packages-update-check-build.yaml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .gitea/workflows/gitea-packages-update-check-build.yaml diff --git a/.gitea/workflows/gitea-packages-update-check-build.yaml b/.gitea/workflows/gitea-packages-update-check-build.yaml new file mode 100644 index 0000000..3d9bf2f --- /dev/null +++ b/.gitea/workflows/gitea-packages-update-check-build.yaml @@ -0,0 +1,26 @@ +on: + pull_request: + types: + - labeled + - opened + - synchronize + - closed + workflow_dispatch: +permissions: + pull-requests: read + +jobs: + build-tool: + runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest + defaults: + run: + working-directory: ./gitea-packages-update-check + if: contains(github.event.pull_request.labels.*.name,'gitea-packages-update-check') + + steps: + - uses: actions/checkout@v3 + - run: go build -o gitea-packages-update-check -ldflags="-s -w" -trimpath + - run: curl --user usbharu:${{ secrets.DEPLOY_TOKEN }} --upload-file gitea-packages-update-check https://git.usbharu.dev/api/packages/usbharu/generic/gitea-packages-update-check/${{ github.sha }}/gitea-packages-update-check + if: github.event.pull_request.merged == true \ No newline at end of file From c4d8f9d1ebf784c42dd66b9651b7246c95e43949 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 13 Mar 2024 18:35:01 +0900 Subject: [PATCH 3/3] =?UTF-8?q?gitea-packages-update-check:=20ci=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/gitea-packages-update-check-build.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitea/workflows/gitea-packages-update-check-build.yaml b/.gitea/workflows/gitea-packages-update-check-build.yaml index 3d9bf2f..fa18237 100644 --- a/.gitea/workflows/gitea-packages-update-check-build.yaml +++ b/.gitea/workflows/gitea-packages-update-check-build.yaml @@ -21,6 +21,9 @@ jobs: steps: - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: "^1.20" - run: go build -o gitea-packages-update-check -ldflags="-s -w" -trimpath - run: curl --user usbharu:${{ secrets.DEPLOY_TOKEN }} --upload-file gitea-packages-update-check https://git.usbharu.dev/api/packages/usbharu/generic/gitea-packages-update-check/${{ github.sha }}/gitea-packages-update-check if: github.event.pull_request.merged == true \ No newline at end of file