diff --git a/.changelog.yml b/.changelog.yml index 740c568..beba96b 100755 --- a/.changelog.yml +++ b/.changelog.yml @@ -1,12 +1,12 @@ # The full repository name -repo: gitea/go-sdk +repo: mvdkleijn/forgejo-sdk -# Service type (gitea or github) -service: gitea +# Service type (forgejo or github) +service: forgejo # Base URL for Gitea instance if using gitea service type (optional) -# Default: https://gitea.com -base-url: https://gitea.com +# Default: https://forgejo.org +base-url: https://forgejo.org # Changelog groups and which labeled PRs to add to each group groups: diff --git a/.gitea/workflows/testing.yml b/.forgejo/workflows/testing.yml similarity index 68% rename from .gitea/workflows/testing.yml rename to .forgejo/workflows/testing.yml index 80ed285..0b13eae 100644 --- a/.gitea/workflows/testing.yml +++ b/.forgejo/workflows/testing.yml @@ -11,9 +11,9 @@ jobs: GOPROXY: "https://goproxy.io" GO111MODULE: "on" HTTP_PROXY: "" - GITEA_SDK_TEST_URL: "http://gitea:3000" - GITEA_SDK_TEST_USERNAME: "test01" - GITEA_SDK_TEST_PASSWORD: "test01" + FORGEJO_SDK_TEST_URL: "http://forgejo:3000" + FORGEJO_SDK_TEST_USERNAME: "test01" + FORGEJO_SDK_TEST_PASSWORD: "test01" steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 @@ -24,11 +24,11 @@ jobs: - run: make vet - run: make ci-lint - run: make build - - run: curl --noproxy "*" http://gitea:3000/api/v1/version # verify connection to instance + - run: curl --noproxy "*" http://forgejo:3000/api/v1/version # verify connection to instance - run: make test services: - gitea: - image: gitea/gitea:1.21.1 + forgejo: + image: codeberg.org/forgejo/forgejo:1.21.5-0 cmd: - bash - -c @@ -46,7 +46,7 @@ jobs: && echo "[repository]" >> /tmp/conf/app.ini && echo "ROOT = /tmp/data/" >> /tmp/conf/app.ini && echo "[server]" >> /tmp/conf/app.ini - && echo "ROOT_URL = http://gitea:3000" >> /tmp/conf/app.ini - && gitea migrate -c /tmp/conf/app.ini - && gitea admin user create --username=test01 --password=test01 --email=test01@gitea.io --admin=true --must-change-password=false --access-token -c /tmp/conf/app.ini - && gitea web -c /tmp/conf/app.ini + && echo "ROOT_URL = http://forgejo:3000" >> /tmp/conf/app.ini + && forgejo migrate -c /tmp/conf/app.ini + && forgejo admin user create --username=test01 --password=test01 --email=test01@forgejo.org --admin=true --must-change-password=false --access-token -c /tmp/conf/app.ini + && forgejo web -c /tmp/conf/app.ini diff --git a/.github/issue_template.md b/.github/issue_template.md index c55f36a..c7deb95 100644 --- a/.github/issue_template.md +++ b/.github/issue_template.md @@ -1,8 +1,6 @@ diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 08714fa..e6b6a3a 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,7 +1,7 @@ Please check the following: 1. Make sure you are targeting the `main` branch, pull requests on release branches are only allowed for bug fixes. -2. Read contributing guidelines: https://gitea.com/gitea/go-sdk/src/branch/main/CONTRIBUTING.md +2. Read contributing guidelines: CONTRIBUTING.md 3. Describe what your pull request does and which issue you're targeting (if any) **You MUST delete the content above including this line before posting, otherwise your pull request will be invalid.** diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index de9b9cb..8254b92 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,36 +1,30 @@ # Contribution Guidelines -## Introduction - -This document explains how to contribute changes to the Gitea project. It assumes you have followed the [installation instructions](https://docs.gitea.io/en-us/install-from-binary/). Sensitive security-related issues should be reported to [security@gitea.io](mailto:security@gitea.io). - ## Bug reports Please search the issues on the issue tracker with a variety of keywords to ensure your bug is not already reported. -If unique, [open an issue](https://gitea.com/gitea/go-sdk/issues/new) and answer the questions so we can understand and reproduce the problematic behavior. +If unique, [open an issue](https://codeberg.org/mvdkleijn/forgejo-sdk/issues/new) and answer the questions so we can understand and reproduce the problematic behavior. -To show us that the issue you are having is in Gitea itself, please write clear, concise instructions so we can reproduce the behavior (even if it seems obvious). The more detailed and specific you are, the faster we can fix the issue. Check out [How to Report Bugs Effectively](http://www.chiark.greenend.org.uk/~sgtatham/bugs.html). +To show us that the issue you are having is in Forgejo SDK itself, please write clear, concise instructions so we can reproduce the behavior (even if it seems obvious). The more detailed and specific you are, the faster we can fix the issue. -Please be kind, remember that Gitea comes at no cost to you, and you're getting free help. +Please be kind, remember that Forgejo SDK comes at no cost to you, and you're getting free help. ## Discuss your design -The project welcomes submissions but please let everyone know what you're working on if you want to change or add something to the Gitea repositories. +The project welcomes submissions but please let everyone know what you're working on if you want to change or add something to the Forgejo SDK repository. -Before starting to write something new for the Gitea project, please [file an issue](https://gitea.com/gitea/go-sdk/issues/new). Significant changes must go through the [change proposal process](https://github.com/go-gitea/proposals) before they can be accepted. - -This process gives everyone a chance to validate the design, helps prevent duplication of effort, and ensures that the idea fits inside the goals for the project and tools. It also checks that the design is sound before code is written; the code review tool is not the place for high-level discussions. +Before starting to write something new for the Forgejo SDK project, please [file an issue](https://coderberg.org/mvdkleijn/forgejo-sdk/issues/new). ## Testing redux -Before sending code out for review, run all the tests for the whole tree to make sure the changes don't break other usage and keep the compatibility on upgrade. To make sure you are running the test suite exactly like we do, you should install the CLI for [Drone CI](https://github.com/drone/drone), as we are using the server for continous testing, following [these instructions](https://exec-runner.docs.drone.io/installation/). After that you can simply call `drone exec` within your working directory and it will try to run the test suite locally. +Before sending code out for review, run all the tests using `make test`, to make sure the changes don't break other usage. In order to run the test, you'll need a test instance. You can create one using `make test-instance`. ## Code review -Changes to Gitea must be reviewed before they are accepted, no matter who makes the change even if it is an owner or a maintainer. We use GitHub's pull request workflow to do that and we also use [LGTM](http://lgtm.co) to ensure every PR is reviewed by at least 2 maintainers. +Changes must be reviewed before they are accepted, no matter who makes the change even if it is an owner or a maintainer. -Please try to make your pull request easy to review for us. Please read the "[How to get faster PR reviews](https://github.com/kubernetes/community/blob/master/contributors/devel/faster_reviews.md)" guide, it has lots of useful tips for any project you may want to contribute. Some of the key points: +Please try to make your pull request easy to review for us. Some of the key points: * Make small pull requests. The smaller, the faster to review and the more likely it will be merged soon. * Don't make changes unrelated to your PR. Maybe there are typos on some comments, maybe refactoring would be welcome on a function... but if that is not related to your PR, please make *another* PR for that. @@ -44,51 +38,14 @@ The sign-off is a simple line at the end of the explanation for the patch. Your Signed-off-by: Joe Smith ``` -Please use your real name, we really dislike pseudonyms or anonymous contributions. We are in the open-source world without secrets. If you set your `user.name` and `user.email` git configs, you can sign your commit automatically with `git commit -s`. - -## Maintainers - -To make sure every PR is checked, we have [team maintainers](https://github.com/orgs/go-gitea/teams/maintainers). Every PR **MUST** be reviewed by at least two maintainers (or owners) before it can get merged. A maintainer should be a contributor of Gitea (or Gogs) and contributed at least 4 accepted PRs. A contributor should apply as a maintainer in the [Gitter develop channel](https://gitter.im/go-gitea/develop). The owners or the team maintainers may invite the contributor. A maintainer should spend some time on code reviews. If a maintainer has no time to do that, they should apply to leave the maintainers team and we will give them the honor of being a member of the [advisors team](https://github.com/orgs/go-gitea/teams/advisors). Of course, if an advisor has time to code review, we will gladly welcome them back to the maintainers team. If a maintainer is inactive for more than 3 months and forgets to leave the maintainers team, the owners may move him or her from the maintainers team to the advisors team. - -## Owners - -Since Gitea is a pure community organization without any company support, to keep the development healthy we will elect three owners every year. All contributors may vote to elect up to three candidates, one of which will be the main owner, and the other two the assistant owners. When the new owners have been elected, the old owners will give up ownership to the newly elected owners. If an owner is unable to do so, the other owners will assist in ceding ownership to the newly elected owners. - -After the election, the new owners should proactively agree with our [CONTRIBUTING](CONTRIBUTING.md) requirements in the [Discord](https://discord.gg/NsatcWJ) #general channel. Below are the words to speak: - -``` -I'm honored to having been elected an owner of Gitea, I agree with [CONTRIBUTING](CONTRIBUTING.md). I will spend part of my time on Gitea and lead the development of Gitea. -``` - -To honor the past owners, here's the history of the owners and the time they served: - -* 2016-11-04 ~ 2017-12-31 - * [Lunny Xiao](https://gitea.com/lunny) - * [Thomas Boerger](https://github.com/tboerger) - * [Kim Carlbäcker](https://github.com/bkcsoft) - -* 2018-01-01 ~ 2018-12-31 - * [Lunny Xiao](https://gitea.com/lunny) - * [Lauris Bukšis-Haberkorns](https://github.com/lafriks) - * [Kim Carlbäcker](https://github.com/bkcsoft) - -* 2019-01-01 ~ 2019-12-31 - * [Lunny Xiao](https://gitea.com/lunny) - * [Lauris Bukšis-Haberkorns](https://github.com/lafriks) - * [Matti Ranta](https://github.com/techknowlogick) - -## Versions - -Gitea has the `master` branch as a tip branch and has version branches such as `v0.9`. `v0.9` is a release branch and we will tag `v0.9.0` for binary download. If `v0.9.0` has bugs, we will accept pull requests on the `v0.9` branch and publish a `v0.9.1` tag, after bringing the bug fix also to the master branch. - -Since the `master` branch is a tip version, if you wish to use Gitea in production, please download the latest release tag version. All the branches will be protected via GitHub, all the PRs to every branch must be reviewed by two maintainers and must pass the automatic tests. +Please use your real name. If you set your `user.name` and `user.email` git configs, you can sign your commit automatically with `git commit -s`. ## Copyright Code that you contribute should use the standard copyright header: ``` -// Copyright 2019 The Gitea Authors. All rights reserved. +// Copyright 2024 The Forgejo Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. ``` diff --git a/LICENSE b/LICENSE index 10aeba4..adf84b8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,4 @@ +Copyright (c) 2024 The Forgejo Authors Copyright (c) 2016 The Gitea Authors Copyright (c) 2014 The Gogs Authors diff --git a/Makefile b/Makefile index d19ef90..f6d90c3 100644 --- a/Makefile +++ b/Makefile @@ -2,38 +2,38 @@ GO ?= go WORK_DIR := $(shell pwd) -GITEA_SDK_TEST_URL ?= http://localhost:3000 -GITEA_SDK_TEST_USERNAME ?= test01 -GITEA_SDK_TEST_PASSWORD ?= test01 +FORGEJO_SDK_TEST_URL ?= http://localhost:3000 +FORGEJO_SDK_TEST_USERNAME ?= test01 +FORGEJO_SDK_TEST_PASSWORD ?= test01 -PACKAGE := code.gitea.io/sdk/gitea +PACKAGE := codeberg.org/mvdkleijn/forgejo-sdk GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.4.0 GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.0 GITEA_VET_PACKAGE ?= code.gitea.io/gitea-vet@v0.2.1 -GITEA_VERSION := 1.21.1 -GITEA_DL := https://dl.gitea.com/gitea/$(GITEA_VERSION)/gitea-$(GITEA_VERSION)- +FORGEJO_VERSION := 1.21.6-0 +FORGEJO_DL := https://codeberg.org/forgejo/forgejo/releases/download/v$(FORGEJO_VERSION)/forgejo-$(FORGEJO_VERSION)- UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Linux) - GITEA_DL := $(GITEA_DL)linux- + FORGEJO_DL := $(FORGEJO_DL)linux- UNAME_P := $(shell uname -p) ifeq ($(UNAME_P),unknown) - GITEA_DL := $(GITEA_DL)amd64 + FORGEJO_DL := $(FORGEJO_DL)amd64 endif ifeq ($(UNAME_P),x86_64) - GITEA_DL := $(GITEA_DL)amd64 + FORGEJO_DL := $(FORGEJO_DL)amd64 endif ifneq ($(filter %86,$(UNAME_P)),) - GITEA_DL := $(GITEA_DL)386 + FORGEJO_DL := $(FORGEJO_DL)386 endif ifneq ($(filter arm%,$(UNAME_P)),) - GITEA_DL := $(GITEA_DL)arm-5 + FORGEJO_DL := $(FORGEJO_DL)arm-5 endif endif ifeq ($(UNAME_S),Darwin) - GITEA_DL := $(GITEA_DL)darwin-10.12-amd64 + FORGEJO_DL := $(FORGEJO_DL)darwin-10.12-amd64 endif .PHONY: all @@ -48,32 +48,32 @@ help: @echo " - fmt format the code" @echo " - lint run golint" @echo " - vet examines Go source code and reports" - @echo " - test run unit tests (need a running gitea)" - @echo " - test-instance start a gitea instance for test" + @echo " - test run unit tests (need a running forgejo)" + @echo " - test-instance start a forgejo instance for test" .PHONY: clean clean: rm -r -f test - cd gitea && $(GO) clean -i ./... + cd forgejo && $(GO) clean -i ./... .PHONY: fmt fmt: find . -name "*.go" -type f | xargs gofmt -s -w; \ - $(GO) run $(GOFUMPT_PACKAGE) -extra -w ./gitea + $(GO) run $(GOFUMPT_PACKAGE) -extra -w ./forgejo .PHONY: vet vet: # Default vet - cd gitea && $(GO) vet $(PACKAGE) + cd forgejo && $(GO) vet $(PACKAGE) # Custom vet - cd gitea && $(GO) get $(GITEA_VET_PACKAGE) - cd gitea && $(GO) build code.gitea.io/gitea-vet - cd gitea && $(GO) vet -vettool=gitea-vet $(PACKAGE) + cd forgejo && $(GO) get $(GITEA_VET_PACKAGE) + cd forgejo && $(GO) build code.gitea.io/gitea-vet + cd forgejo && $(GO) vet -vettool=gitea-vet $(PACKAGE) .PHONY: ci-lint ci-lint: - @cd gitea/; echo -n "gofumpt ...";\ + @cd forgejo/; echo -n "gofumpt ...";\ diff=$$($(GO) run $(GOFUMPT_PACKAGE) -extra -l .); \ if [ -n "$$diff" ]; then \ echo; echo "Not gofumpt-ed"; \ @@ -88,17 +88,17 @@ ci-lint: .PHONY: test test: - @export GITEA_SDK_TEST_URL=${GITEA_SDK_TEST_URL}; export GITEA_SDK_TEST_USERNAME=${GITEA_SDK_TEST_USERNAME}; export GITEA_SDK_TEST_PASSWORD=${GITEA_SDK_TEST_PASSWORD}; \ - if [ -z "$(shell curl --noproxy "*" "${GITEA_SDK_TEST_URL}/api/v1/version" 2> /dev/null)" ]; then \echo "No test-instance detected!"; exit 1; else \ - cd gitea && $(GO) test -race -cover -coverprofile coverage.out; \ + @export FORGEJO_SDK_TEST_URL=${FORGEJO_SDK_TEST_URL}; export FORGEJO_SDK_TEST_USERNAME=${FORGEJO_SDK_TEST_USERNAME}; export FORGEJO_SDK_TEST_PASSWORD=${FORGEJO_SDK_TEST_PASSWORD}; \ + if [ -z "$(shell curl --noproxy "*" "${FORGEJO_SDK_TEST_URL}/api/v1/version" 2> /dev/null)" ]; then \echo "No test-instance detected!"; exit 1; else \ + cd forgejo && $(GO) test -race -cover -coverprofile coverage.out; \ fi .PHONY: test-instance test-instance: rm -f -r ${WORK_DIR}/test 2> /dev/null; \ mkdir -p ${WORK_DIR}/test/conf/ ${WORK_DIR}/test/data/ - wget ${GITEA_DL} -O ${WORK_DIR}/test/gitea-main; \ - chmod +x ${WORK_DIR}/test/gitea-main; \ + wget ${FORGEJO_DL} -O ${WORK_DIR}/test/forgejo-main; \ + chmod +x ${WORK_DIR}/test/forgejo-main; \ echo "[security]" > ${WORK_DIR}/test/conf/app.ini; \ echo "INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE1NTg4MzY4ODB9.LoKQyK5TN_0kMJFVHWUW0uDAyoGjDP6Mkup4ps2VJN4" >> ${WORK_DIR}/test/conf/app.ini; \ echo "INSTALL_LOCK = true" >> ${WORK_DIR}/test/conf/app.ini; \ @@ -109,16 +109,16 @@ test-instance: echo "[repository]" >> ${WORK_DIR}/test/conf/app.ini; \ echo "ROOT = ${WORK_DIR}/test/data/" >> ${WORK_DIR}/test/conf/app.ini; \ echo "[server]" >> ${WORK_DIR}/test/conf/app.ini; \ - echo "ROOT_URL = ${GITEA_SDK_TEST_URL}" >> ${WORK_DIR}/test/conf/app.ini; \ - ${WORK_DIR}/test/gitea-main migrate -c ${WORK_DIR}/test/conf/app.ini; \ - ${WORK_DIR}/test/gitea-main admin user create --username=${GITEA_SDK_TEST_USERNAME} --password=${GITEA_SDK_TEST_PASSWORD} --email=test01@gitea.io --admin=true --must-change-password=false --access-token -c ${WORK_DIR}/test/conf/app.ini; \ - ${WORK_DIR}/test/gitea-main web -c ${WORK_DIR}/test/conf/app.ini + echo "ROOT_URL = ${FORGEJO_SDK_TEST_URL}" >> ${WORK_DIR}/test/conf/app.ini; \ + ${WORK_DIR}/test/forgejo-main migrate -c ${WORK_DIR}/test/conf/app.ini; \ + ${WORK_DIR}/test/forgejo-main admin user create --username=${FORGEJO_SDK_TEST_USERNAME} --password=${FORGEJO_SDK_TEST_PASSWORD} --email=test01@forgejo.org --admin=true --must-change-password=false --access-token -c ${WORK_DIR}/test/conf/app.ini; \ + ${WORK_DIR}/test/forgejo-main web -c ${WORK_DIR}/test/conf/app.ini .PHONY: bench bench: - cd gitea && $(GO) test -run=XXXXXX -benchtime=10s -bench=. || exit 1 + cd forgejo && $(GO) test -run=XXXXXX -benchtime=10s -bench=. || exit 1 .PHONY: build build: - cd gitea && $(GO) build + cd forgejo && $(GO) build diff --git a/README.md b/README.md index c79a89f..88a23dc 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,27 @@ -# Gitea SDK for Go +# Forgejo SDK for Go [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) -[![Release](https://raster.shields.io/badge/dynamic/json.svg?label=release&url=https://gitea.com/api/v1/repos/gitea/go-sdk/releases&query=$[0].tag_name)](https://gitea.com/gitea/go-sdk/releases) -[![Join the chat at https://img.shields.io/discord/322538954119184384.svg](https://img.shields.io/discord/322538954119184384.svg)](https://discord.gg/Gitea) -[![Go Report Card](https://goreportcard.com/badge/code.gitea.io/sdk)](https://goreportcard.com/report/code.gitea.io/sdk) -[![GoDoc](https://godoc.org/code.gitea.io/sdk/gitea?status.svg)](https://godoc.org/code.gitea.io/sdk/gitea) +[![Go Report Card](https://goreportcard.com/badge/codeberg.org/mvdkleijn/forgejo-sdk)](https://goreportcard.com/report/codeberg.org/mvdkleijn/forgejo-sdk) +[![GoDoc](https://godoc.org/codeberg.org/mvdkleijn/forgejo-sdk/forgejo?status.svg)](https://godoc.org/codeberg.org/mvdkleijn/forgejo-sdk/forgejo) -This project acts as a client SDK implementation written in Go to interact with the Gitea API implementation. For further informations take a look at the current [documentation](https://pkg.go.dev/code.gitea.io/sdk/gitea). +This project acts as a client SDK implementation written in Go to interact with the Forgejo API implementation. For further informations take a look at the current [documentation](https://pkg.go.dev/codeberg.org/mvdkleijn/forgejo-sdk/forgejo). Note: function arguments are escaped by the SDK. ## Use it ```go -import "code.gitea.io/sdk/gitea" +import "codeberg.org/mvdkleijn/forgejo-sdk/forgejo" ``` ## Version Requirements * go >= 1.13 - * gitea >= 1.11 + * forgejo >= 1.11 ## Contributing Fork -> Patch -> Push -> Pull Request -## Authors - -* [Maintainers](https://github.com/orgs/go-gitea/people) -* [Contributors](https://github.com/go-gitea/go-sdk/graphs/contributors) - ## License This project is under the MIT License. See the [LICENSE](LICENSE) file for the full license text. diff --git a/gitea/admin_cron.go b/forgejo/admin_cron.go similarity index 88% rename from gitea/admin_cron.go rename to forgejo/admin_cron.go index 84316da..7ef7899 100644 --- a/gitea/admin_cron.go +++ b/forgejo/admin_cron.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/admin_org.go b/forgejo/admin_org.go similarity index 86% rename from gitea/admin_org.go rename to forgejo/admin_org.go index 26bf81f..f8c499f 100644 --- a/gitea/admin_org.go +++ b/forgejo/admin_org.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/admin_repo.go b/forgejo/admin_repo.go similarity index 79% rename from gitea/admin_repo.go rename to forgejo/admin_repo.go index 8666690..6d2040e 100644 --- a/gitea/admin_repo.go +++ b/forgejo/admin_repo.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2015 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/admin_test.go b/forgejo/admin_test.go similarity index 87% rename from gitea/admin_test.go rename to forgejo/admin_test.go index e5a49e3..bd8eb72 100644 --- a/gitea/admin_test.go +++ b/forgejo/admin_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/admin_user.go b/forgejo/admin_user.go similarity index 96% rename from gitea/admin_user.go rename to forgejo/admin_user.go index 172f064..57f23df 100644 --- a/gitea/admin_user.go +++ b/forgejo/admin_user.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/agent.go b/forgejo/agent.go similarity index 79% rename from gitea/agent.go rename to forgejo/agent.go index 7622ece..77d738b 100644 --- a/gitea/agent.go +++ b/forgejo/agent.go @@ -1,10 +1,14 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. //go:build !windows -package gitea +package forgejo import ( "fmt" diff --git a/gitea/agent_windows.go b/forgejo/agent_windows.go similarity index 75% rename from gitea/agent_windows.go rename to forgejo/agent_windows.go index 135dc4f..7cfc6fa 100644 --- a/gitea/agent_windows.go +++ b/forgejo/agent_windows.go @@ -1,10 +1,14 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. //go:build windows -package gitea +package forgejo import ( "fmt" diff --git a/gitea/attachment.go b/forgejo/attachment.go similarity index 94% rename from gitea/attachment.go rename to forgejo/attachment.go index f02c721..95e1ac1 100644 --- a/gitea/attachment.go +++ b/forgejo/attachment.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2017 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea // import "code.gitea.io/sdk/gitea" +package forgejo // import "code.codeberg.org/mvdkleijn/forgejo-sdk" import ( "bytes" "encoding/json" diff --git a/gitea/client.go b/forgejo/client.go similarity index 95% rename from gitea/client.go rename to forgejo/client.go index adbadc7..35fa6ac 100644 --- a/gitea/client.go +++ b/forgejo/client.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2014 The Gogs Authors. All rights reserved. // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" @@ -28,7 +32,7 @@ func Version() string { return "0.16.0" } -// Client represents a thread-safe Gitea API client. +// Client represents a thread-safe Forgejo API client. type Client struct { url string accessToken string @@ -44,10 +48,10 @@ type Client struct { mutex sync.RWMutex serverVersion *version.Version getVersionOnce sync.Once - ignoreVersion bool // only set by SetGiteaVersion so don't need a mutex lock + ignoreVersion bool // only set by SetForgejoVersion so don't need a mutex lock } -// Response represents the gitea response +// Response represents the forgejo response type Response struct { *http.Response @@ -61,7 +65,7 @@ type Response struct { type ClientOption func(*Client) error // NewClient initializes and returns a API client. -// Usage of all gitea.Client methods is concurrency-safe. +// Usage of all forgejo.Client methods is concurrency-safe. func NewClient(url string, options ...ClientOption) (*Client, error) { client := &Client{ url: strings.TrimSuffix(url, "/"), @@ -347,7 +351,7 @@ func (c *Client) doRequest(method, path string, header http.Header, body io.Read req.Header.Set("Authorization", "token "+c.accessToken) } if len(c.otp) != 0 { - req.Header.Set("X-GITEA-OTP", c.otp) + req.Header.Set("X-FORGEJO-OTP", c.otp) } if len(c.username) != 0 { req.SetBasicAuth(c.username, c.password) @@ -411,7 +415,7 @@ func statusCodeToErr(resp *Response) (body []byte, err error) { path := resp.Request.URL.Path method := resp.Request.Method header := resp.Request.Header - return data, fmt.Errorf("Unknown API Error: %d\nRequest: '%s' with '%s' method '%s' header and '%s' body", resp.StatusCode, path, method, header, string(data)) + return data, fmt.Errorf("unknown API Error: %d\nRequest: '%s' with '%s' method '%s' header and '%s' body", resp.StatusCode, path, method, header, string(data)) } if msg, ok := errMap["message"]; ok { diff --git a/gitea/client_test.go b/forgejo/client_test.go similarity index 80% rename from gitea/client_test.go rename to forgejo/client_test.go index 9470690..8c80e22 100644 --- a/gitea/client_test.go +++ b/forgejo/client_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2023 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "net/http" @@ -12,6 +16,7 @@ import ( "github.com/stretchr/testify/assert" ) +// TODO: change urls to something suitable for Forgejo func TestParsedPaging(t *testing.T) { resp := newResponse(&http.Response{ Header: http.Header{ diff --git a/forgejo/doc.go b/forgejo/doc.go new file mode 100644 index 0000000..549a598 --- /dev/null +++ b/forgejo/doc.go @@ -0,0 +1,13 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +// Copyright 2016 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +// package forgejo implements a client for the Forgejo API. +// The version corresponds to the highest supported version +// of the forgejo API, but backwards-compatibility is mostly +// given. +package forgejo // import "code.codeberg.org/mvdkleijn/forgejo-sdk" diff --git a/gitea/fork.go b/forgejo/fork.go similarity index 89% rename from gitea/fork.go rename to forgejo/fork.go index 0373c35..f5bfacf 100644 --- a/gitea/fork.go +++ b/forgejo/fork.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2016 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/git_blob.go b/forgejo/git_blob.go similarity index 82% rename from gitea/git_blob.go rename to forgejo/git_blob.go index 7668672..2a820cf 100644 --- a/gitea/git_blob.go +++ b/forgejo/git_blob.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/git_hook.go b/forgejo/git_hook.go similarity index 92% rename from gitea/git_hook.go rename to forgejo/git_hook.go index d8fbf71..d35fd11 100644 --- a/gitea/git_hook.go +++ b/forgejo/git_hook.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/forgejo/go.mod b/forgejo/go.mod new file mode 100644 index 0000000..01eb1a1 --- /dev/null +++ b/forgejo/go.mod @@ -0,0 +1,18 @@ +module codeberg.org/mvdkleijn/forgejo-sdk + +go 1.21 + +require ( + github.com/davidmz/go-pageant v1.0.2 + github.com/go-fed/httpsig v1.1.0 + github.com/hashicorp/go-version v1.6.0 + github.com/stretchr/testify v1.7.0 + golang.org/x/crypto v0.17.0 +) + +require ( + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/sys v0.15.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect +) diff --git a/gitea/go.sum b/forgejo/go.sum similarity index 56% rename from gitea/go.sum rename to forgejo/go.sum index b8a46a5..3469c7e 100644 --- a/gitea/go.sum +++ b/forgejo/go.sum @@ -11,51 +11,24 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/gitea/helper.go b/forgejo/helper.go similarity index 72% rename from gitea/helper.go rename to forgejo/helper.go index ff8038b..48d28e6 100644 --- a/gitea/helper.go +++ b/forgejo/helper.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo // OptionalBool convert a bool to a bool reference func OptionalBool(v bool) *bool { diff --git a/gitea/hook.go b/forgejo/hook.go similarity index 96% rename from gitea/hook.go rename to forgejo/hook.go index fe42b7c..95561ee 100644 --- a/gitea/hook.go +++ b/forgejo/hook.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2014 The Gogs Authors. All rights reserved. // Copyright 2017 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" @@ -24,7 +28,7 @@ type Hook struct { Created time.Time `json:"created_at"` } -// HookType represent all webhook types gitea currently offer +// HookType represent all webhook types forgejo currently offer type HookType string const ( @@ -32,6 +36,8 @@ const ( HookTypeDingtalk HookType = "dingtalk" // HookTypeDiscord webhook that discord understand HookTypeDiscord HookType = "discord" + // HookTypeForgejo webhook that forgejo understand + HookTypeForgejo HookType = "forgejo" // HookTypeGitea webhook that gitea understand HookTypeGitea HookType = "gitea" // HookTypeGogs webhook that gogs understand diff --git a/gitea/hook_validate.go b/forgejo/hook_validate.go similarity index 82% rename from gitea/hook_validate.go rename to forgejo/hook_validate.go index 5ef6149..b3dcc44 100644 --- a/gitea/hook_validate.go +++ b/forgejo/hook_validate.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" @@ -13,7 +17,7 @@ import ( "net/http" ) -// VerifyWebhookSignature verifies that a payload matches the X-Gitea-Signature based on a secret +// VerifyWebhookSignature verifies that a payload matches the X-Forgejo-Signature based on a secret func VerifyWebhookSignature(secret, expected string, payload []byte) (bool, error) { hash := hmac.New(sha256.New, []byte(secret)) if _, err := hash.Write(payload); err != nil { @@ -26,7 +30,7 @@ func VerifyWebhookSignature(secret, expected string, payload []byte) (bool, erro return hmac.Equal(hash.Sum(nil), expectedSum), nil } -// VerifyWebhookSignatureMiddleware is a http.Handler for verifying X-Gitea-Signature on incoming webhooks +// VerifyWebhookSignatureMiddleware is a http.Handler for verifying X-Forgejo-Signature on incoming webhooks func VerifyWebhookSignatureMiddleware(secret string) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -36,7 +40,7 @@ func VerifyWebhookSignatureMiddleware(secret string) func(http.Handler) http.Han return } - expected := r.Header.Get("X-Gitea-Signature") + expected := r.Header.Get("X-Forgejo-Signature") if expected == "" { http.Error(w, "no signature found", http.StatusBadRequest) return diff --git a/gitea/hook_validate_test.go b/forgejo/hook_validate_test.go similarity index 92% rename from gitea/hook_validate_test.go rename to forgejo/hook_validate_test.go index 946d4c2..88d6fff 100644 --- a/gitea/hook_validate_test.go +++ b/forgejo/hook_validate_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "crypto/hmac" @@ -114,7 +118,7 @@ func TestVerifyWebhookSignatureHandler(t *testing.T) { assert.NoError(t, err, "should create request") if tc.Signature != "" { - req.Header.Set("X-Gitea-Signature", tc.Signature) + req.Header.Set("X-Forgejo-Signature", tc.Signature) } resp, err := http.DefaultClient.Do(req) diff --git a/gitea/httpsign.go b/forgejo/httpsign.go similarity index 96% rename from gitea/httpsign.go rename to forgejo/httpsign.go index 49b0059..efeece5 100644 --- a/gitea/httpsign.go +++ b/forgejo/httpsign.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "crypto" @@ -180,7 +184,7 @@ func (c *Client) SignRequest(r *http.Request) error { } // sign the request, use the fingerprint if we don't have a certificate - keyID := "gitea" + keyID := "forgejo" if !c.httpsigner.cert { keyID = ssh.FingerprintSHA256(c.httpsigner.Signer.PublicKey()) } diff --git a/gitea/issue.go b/forgejo/issue.go similarity index 98% rename from gitea/issue.go rename to forgejo/issue.go index 603d23d..e5a9564 100644 --- a/gitea/issue.go +++ b/forgejo/issue.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2016 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/issue_comment.go b/forgejo/issue_comment.go similarity index 96% rename from gitea/issue_comment.go rename to forgejo/issue_comment.go index 8131a6e..802a468 100644 --- a/gitea/issue_comment.go +++ b/forgejo/issue_comment.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2016 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/issue_comment_test.go b/forgejo/issue_comment_test.go similarity index 94% rename from gitea/issue_comment_test.go rename to forgejo/issue_comment_test.go index 10a96d0..cd30f38 100644 --- a/gitea/issue_comment_test.go +++ b/forgejo/issue_comment_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/issue_label.go b/forgejo/issue_label.go similarity index 97% rename from gitea/issue_label.go rename to forgejo/issue_label.go index f343ee5..2fd7eb5 100644 --- a/gitea/issue_label.go +++ b/forgejo/issue_label.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2016 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/issue_label_test.go b/forgejo/issue_label_test.go similarity index 95% rename from gitea/issue_label_test.go rename to forgejo/issue_label_test.go index a5daed6..e23550c 100644 --- a/gitea/issue_label_test.go +++ b/forgejo/issue_label_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/issue_milestone.go b/forgejo/issue_milestone.go similarity index 97% rename from gitea/issue_milestone.go rename to forgejo/issue_milestone.go index 4e0d79a..26d59b8 100644 --- a/gitea/issue_milestone.go +++ b/forgejo/issue_milestone.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2016 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/issue_milestone_test.go b/forgejo/issue_milestone_test.go similarity index 94% rename from gitea/issue_milestone_test.go rename to forgejo/issue_milestone_test.go index e751689..17a5ec5 100644 --- a/gitea/issue_milestone_test.go +++ b/forgejo/issue_milestone_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/issue_reaction.go b/forgejo/issue_reaction.go similarity index 95% rename from gitea/issue_reaction.go rename to forgejo/issue_reaction.go index b45c066..c7c4c1d 100644 --- a/gitea/issue_reaction.go +++ b/forgejo/issue_reaction.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/issue_stopwatch.go b/forgejo/issue_stopwatch.go similarity index 92% rename from gitea/issue_stopwatch.go rename to forgejo/issue_stopwatch.go index ebb0b8a..737ed3b 100644 --- a/gitea/issue_stopwatch.go +++ b/forgejo/issue_stopwatch.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/issue_subscription.go b/forgejo/issue_subscription.go similarity index 94% rename from gitea/issue_subscription.go rename to forgejo/issue_subscription.go index 86853c7..a103c43 100644 --- a/gitea/issue_subscription.go +++ b/forgejo/issue_subscription.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/issue_subscription_test.go b/forgejo/issue_subscription_test.go similarity index 90% rename from gitea/issue_subscription_test.go rename to forgejo/issue_subscription_test.go index 585e9f3..ef5e153 100644 --- a/gitea/issue_subscription_test.go +++ b/forgejo/issue_subscription_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/issue_template.go b/forgejo/issue_template.go similarity index 95% rename from gitea/issue_template.go rename to forgejo/issue_template.go index e6ac1e9..9100c35 100644 --- a/gitea/issue_template.go +++ b/forgejo/issue_template.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/issue_test.go b/forgejo/issue_test.go similarity index 94% rename from gitea/issue_test.go rename to forgejo/issue_test.go index 1a77558..b707aad 100644 --- a/gitea/issue_test.go +++ b/forgejo/issue_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" @@ -18,7 +22,7 @@ func TestIssue(t *testing.T) { c := newTestClient() createIssue(t, c) - // Little sleep in order to give some time for gitea to properly store all information on database. Without this sleep, CI is a bit unstable + // Little sleep in order to give some time for forgejo to properly store all information on database. Without this sleep, CI is a bit unstable time.Sleep(100 * time.Millisecond) editIssues(t, c) listIssues(t, c) diff --git a/gitea/issue_tracked_time.go b/forgejo/issue_tracked_time.go similarity index 96% rename from gitea/issue_tracked_time.go rename to forgejo/issue_tracked_time.go index c558516..d4341b7 100644 --- a/gitea/issue_tracked_time.go +++ b/forgejo/issue_tracked_time.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2017 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/list_options.go b/forgejo/list_options.go similarity index 81% rename from gitea/list_options.go rename to forgejo/list_options.go index fb1aff4..049ec7d 100644 --- a/gitea/list_options.go +++ b/forgejo/list_options.go @@ -1,15 +1,19 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" "net/url" ) -// ListOptions options for using Gitea's API pagination +// ListOptions options for using Forgejo's API pagination type ListOptions struct { // Setting Page to -1 disables pagination on endpoints that support it. // Page numbering starts at 1. diff --git a/forgejo/main_test.go b/forgejo/main_test.go new file mode 100644 index 0000000..f8748c0 --- /dev/null +++ b/forgejo/main_test.go @@ -0,0 +1,168 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package forgejo + +import ( + "fmt" + "io" + "log" + "net/http" + "os" + "os/exec" + "path/filepath" + "runtime" + "strconv" + "testing" +) + +func getForgejoURL() string { + return os.Getenv("FORGEJO_SDK_TEST_URL") +} + +func getForgejoToken() string { + return os.Getenv("FORGEJO_SDK_TEST_TOKEN") +} + +func getForgejoUsername() string { + return os.Getenv("FORGEJO_SDK_TEST_USERNAME") +} + +func getForgejoPassword() string { + return os.Getenv("FORGEJO_SDK_TEST_PASSWORD") +} + +func enableRunForgejo() bool { + r, _ := strconv.ParseBool(os.Getenv("FORGEJO_SDK_TEST_RUN_FORGEJO")) + return r +} + +func newTestClient() *Client { + c, _ := NewClient(getForgejoURL(), newTestClientAuth()) + return c +} + +func newTestClientAuth() ClientOption { + token := getForgejoToken() + if token == "" { + return SetBasicAuth(getForgejoUsername(), getForgejoPassword()) + } + return SetToken(getForgejoToken()) +} + +// TODO: replace with proper forgejo path +func forgejoMasterPath() string { + switch runtime.GOOS { + case "darwin": + return fmt.Sprintf("https://codeberg.org/forgejo/forgejo/releases/download/v1.21.6-0/forgejo-1.21.6-0-%s", runtime.GOARCH) + case "linux": + return fmt.Sprintf("https://codeberg.org/forgejo/forgejo/releases/download/v1.21.6-0/forgejo-1.21.6-0-linux-%s", runtime.GOARCH) + case "windows": + return fmt.Sprintf("https://codeberg.org/forgejo/forgejo/releases/download/v1.21.6-0/forgejo-1.21.6-0-%s.exe", runtime.GOARCH) + } + return "" +} + +func downForgejo() (string, error) { + for i := 3; i > 0; i-- { + resp, err := http.Get(forgejoMasterPath()) + if err != nil { + continue + } + defer resp.Body.Close() + + f, err := os.CreateTemp(os.TempDir(), "forgejo") + if err != nil { + continue + } + _, err = io.Copy(f, resp.Body) + f.Close() + if err != nil { + continue + } + + if err = os.Chmod(f.Name(), 0o700); err != nil { + return "", err + } + + return f.Name(), nil + } + + return "", fmt.Errorf("Download forgejo from %v failed", forgejoMasterPath()) +} + +func runForgejo() (*os.Process, error) { + log.Println("Downloading Forgejo from", forgejoMasterPath()) + p, err := downForgejo() + if err != nil { + log.Fatal(err) + } + + forgejoDir := filepath.Dir(p) + cfgDir := filepath.Join(forgejoDir, "custom", "conf") + err = os.MkdirAll(cfgDir, os.ModePerm) + if err != nil { + log.Fatal(err) + } + cfg, err := os.Create(filepath.Join(cfgDir, "app.ini")) + if err != nil { + log.Fatal(err) + } + + _, err = cfg.WriteString(`[security] +INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE1NTg4MzY4ODB9.LoKQyK5TN_0kMJFVHWUW0uDAyoGjDP6Mkup4ps2VJN4 +INSTALL_LOCK = true +SECRET_KEY = 2crAW4UANgvLipDS6U5obRcFosjSJHQANll6MNfX7P0G3se3fKcCwwK3szPyGcbo +[database] +DB_TYPE = sqlite3 +[log] +MODE = console +LEVEL = Trace +REDIRECT_MACARON_LOG = true +MACARON = , +ROUTER = ,`) + cfg.Close() + if err != nil { + log.Fatal(err) + } + + log.Println("Run forgejo migrate", p) + err = exec.Command(p, "migrate").Run() + if err != nil { + log.Fatal(err) + } + + log.Println("Run forgejo admin", p) + err = exec.Command(p, "admin", "create-user", "--username=test01", "--password=test01", "--email=test01@forgejo.org", "--admin=true", "--must-change-password=false", "--access-token").Run() + if err != nil { + log.Fatal(err) + } + + log.Println("Start Forgejo", p) + return os.StartProcess(filepath.Base(p), []string{}, &os.ProcAttr{ + Dir: forgejoDir, + }) +} + +func TestMain(m *testing.M) { + if enableRunForgejo() { + p, err := runForgejo() + if err != nil { + log.Fatal(err) + return + } + defer func() { + if err := p.Kill(); err != nil { + log.Fatal(err) + } + }() + } + log.Printf("testing with %v, %v, %v\n", getForgejoURL(), getForgejoUsername(), getForgejoPassword()) + exitCode := m.Run() + os.Exit(exitCode) +} diff --git a/gitea/notifications.go b/forgejo/notifications.go similarity index 96% rename from gitea/notifications.go rename to forgejo/notifications.go index 640cc4d..6e0227d 100644 --- a/gitea/notifications.go +++ b/forgejo/notifications.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" @@ -160,7 +164,7 @@ func (c *Client) GetNotification(id int64) (*NotificationThread, *Response, erro // ReadNotification mark notification thread as read by ID // It optionally takes a second argument if status has to be set other than 'read' -// The relevant notification will be returned as the first parameter when the Gitea server is 1.16.0 or higher. +// The relevant notification will be returned as the first parameter when the Forgejo server is 1.16.0 or higher. func (c *Client) ReadNotification(id int64, status ...NotifyStatus) (*NotificationThread, *Response, error) { if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil { return nil, nil, err @@ -194,7 +198,7 @@ func (c *Client) ListNotifications(opt ListNotificationOptions) ([]*Notification } // ReadNotifications mark notification threads as read -// The relevant notifications will only be returned as the first parameter when the Gitea server is 1.16.0 or higher. +// The relevant notifications will only be returned as the first parameter when the Forgejo server is 1.16.0 or higher. func (c *Client) ReadNotifications(opt MarkNotificationOptions) ([]*NotificationThread, *Response, error) { if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil { return nil, nil, err @@ -233,7 +237,7 @@ func (c *Client) ListRepoNotifications(owner, repo string, opt ListNotificationO } // ReadRepoNotifications mark notification threads as read on a specific repo -// The relevant notifications will only be returned as the first parameter when the Gitea server is 1.16.0 or higher. +// The relevant notifications will only be returned as the first parameter when the Forgejo server is 1.16.0 or higher. func (c *Client) ReadRepoNotifications(owner, repo string, opt MarkNotificationOptions) ([]*NotificationThread, *Response, error) { if err := escapeValidatePathSegments(&owner, &repo); err != nil { return nil, nil, err diff --git a/gitea/notifications_test.go b/forgejo/notifications_test.go similarity index 96% rename from gitea/notifications_test.go rename to forgejo/notifications_test.go index ab5451d..f5ef300 100644 --- a/gitea/notifications_test.go +++ b/forgejo/notifications_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/oauth2.go b/forgejo/oauth2.go similarity index 94% rename from gitea/oauth2.go rename to forgejo/oauth2.go index 86e2568..b720a12 100644 --- a/gitea/oauth2.go +++ b/forgejo/oauth2.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/oauth2_test.go b/forgejo/oauth2_test.go similarity index 93% rename from gitea/oauth2_test.go rename to forgejo/oauth2_test.go index c3641eb..08125e0 100644 --- a/gitea/oauth2_test.go +++ b/forgejo/oauth2_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/org.go b/forgejo/org.go similarity index 96% rename from gitea/org.go rename to forgejo/org.go index 82e1bf5..999fd02 100644 --- a/gitea/org.go +++ b/forgejo/org.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/org_action.go b/forgejo/org_action.go similarity index 82% rename from gitea/org_action.go rename to forgejo/org_action.go index a1dec28..4a78632 100644 --- a/gitea/org_action.go +++ b/forgejo/org_action.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2023 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/org_member.go b/forgejo/org_member.go similarity index 96% rename from gitea/org_member.go rename to forgejo/org_member.go index 79dad4e..5d55cc5 100644 --- a/gitea/org_member.go +++ b/forgejo/org_member.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/org_member_test.go b/forgejo/org_member_test.go similarity index 91% rename from gitea/org_member_test.go rename to forgejo/org_member_test.go index 3fef6cd..4507c38 100644 --- a/gitea/org_member_test.go +++ b/forgejo/org_member_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/org_team.go b/forgejo/org_team.go similarity index 96% rename from gitea/org_team.go rename to forgejo/org_team.go index 9c02e85..4ad373a 100644 --- a/gitea/org_team.go +++ b/forgejo/org_team.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" @@ -23,7 +27,7 @@ type Team struct { Units []RepoUnitType `json:"units"` } -// RepoUnitType represent all unit types of a repo gitea currently offer +// RepoUnitType represent all unit types of a repo forgejo currently offer type RepoUnitType string const ( @@ -113,7 +117,7 @@ func (c *Client) SearchOrgTeams(org string, opt *SearchTeamsOptions) ([]*Team, * return nil, resp, err } if !responseBody.OK { - return nil, resp, fmt.Errorf("gitea error: %v", responseBody.Error) + return nil, resp, fmt.Errorf("forgejo error: %v", responseBody.Error) } return responseBody.Data, resp, err } diff --git a/gitea/org_team_test.go b/forgejo/org_team_test.go similarity index 89% rename from gitea/org_team_test.go rename to forgejo/org_team_test.go index 3348a13..2391bcd 100644 --- a/gitea/org_team_test.go +++ b/forgejo/org_team_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2021 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/org_test.go b/forgejo/org_test.go similarity index 86% rename from gitea/org_test.go rename to forgejo/org_test.go index 93a1ba7..d45e66e 100644 --- a/gitea/org_test.go +++ b/forgejo/org_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2021 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "testing" diff --git a/gitea/package.go b/forgejo/package.go similarity index 94% rename from gitea/package.go rename to forgejo/package.go index 41ffdee..414b861 100644 --- a/gitea/package.go +++ b/forgejo/package.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2023 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/package_test.go b/forgejo/package_test.go similarity index 88% rename from gitea/package_test.go rename to forgejo/package_test.go index 91c21f0..f28e63a 100644 --- a/gitea/package_test.go +++ b/forgejo/package_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2023 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" @@ -28,14 +32,14 @@ func createTestPackage(t *testing.T, c *Client) error { reader := bytes.NewReader([]byte("Hello world!")) - url := fmt.Sprintf("%s/api/packages/PackageOrg/generic/MyPackage/v1/file1.txt", os.Getenv("GITEA_SDK_TEST_URL")) + url := fmt.Sprintf("%s/api/packages/PackageOrg/generic/MyPackage/v1/file1.txt", os.Getenv("FORGEJO_SDK_TEST_URL")) req, err := http.NewRequest(http.MethodPut, url, reader) if err != nil { log.Println(err) return err } - req.SetBasicAuth(os.Getenv("GITEA_SDK_TEST_USERNAME"), os.Getenv("GITEA_SDK_TEST_PASSWORD")) + req.SetBasicAuth(os.Getenv("FORGEJO_SDK_TEST_USERNAME"), os.Getenv("FORGEJO_SDK_TEST_PASSWORD")) response, err := client.Do(req) if err != nil { return err diff --git a/gitea/pull.go b/forgejo/pull.go similarity index 97% rename from gitea/pull.go rename to forgejo/pull.go index 8ca8164..86a278a 100644 --- a/gitea/pull.go +++ b/forgejo/pull.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2016 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" @@ -198,7 +202,7 @@ func (opt EditPullRequestOption) Validate(c *Client) error { } if len(opt.Base) != 0 { if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil { - return fmt.Errorf("can not change base gitea to old") + return fmt.Errorf("can not change base forgejo to old") } } return nil @@ -321,7 +325,7 @@ func (c *Client) GetPullRequestPatch(owner, repo string, index int64) ([]byte, * return c.getPullRequestDiffOrPatch(owner, repo, pullRequestDiffTypePatch, index, PullRequestDiffOptions{}) } -// GetPullRequestDiff gets the diff of a PR. For Gitea >= 1.16, you must set includeBinary to get an applicable diff +// GetPullRequestDiff gets the diff of a PR. For Forgejo >= 1.16, you must set includeBinary to get an applicable diff func (c *Client) GetPullRequestDiff(owner, repo string, index int64, opts PullRequestDiffOptions) ([]byte, *Response, error) { return c.getPullRequestDiffOrPatch(owner, repo, pullRequestDiffTypeDiff, index, opts) } @@ -347,7 +351,7 @@ func (c *Client) ListPullRequestCommits(owner, repo string, index int64, opt Lis // fixPullHeadSha is a workaround for https://github.com/go-gitea/gitea/issues/12675 // When no head sha is available, this is because the branch got deleted in the base repo. // pr.Head.Ref points in this case not to the head repo branch name, but the base repo ref, -// which stays available to resolve the commit sha. This is fixed for gitea >= 1.14.0 +// which stays available to resolve the commit sha. This is fixed for forgejo >= 1.14.0 func fixPullHeadSha(client *Client, pr *PullRequest) error { if pr.Base != nil && pr.Base.Repository != nil && pr.Base.Repository.Owner != nil && pr.Head != nil && pr.Head.Ref != "" && pr.Head.Sha == "" { diff --git a/gitea/pull_review.go b/forgejo/pull_review.go similarity index 98% rename from gitea/pull_review.go rename to forgejo/pull_review.go index 6d32c4f..824aa49 100644 --- a/gitea/pull_review.go +++ b/forgejo/pull_review.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/pull_review_test.go b/forgejo/pull_review_test.go similarity index 97% rename from gitea/pull_review_test.go rename to forgejo/pull_review_test.go index 949ab9d..79bf632 100644 --- a/gitea/pull_review_test.go +++ b/forgejo/pull_review_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/pull_test.go b/forgejo/pull_test.go similarity index 97% rename from gitea/pull_test.go rename to forgejo/pull_test.go index 3bdcd92..1b11329 100644 --- a/gitea/pull_test.go +++ b/forgejo/pull_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/release.go b/forgejo/release.go similarity index 96% rename from gitea/release.go rename to forgejo/release.go index f3707b7..f9839b9 100644 --- a/gitea/release.go +++ b/forgejo/release.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2016 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" @@ -193,7 +197,7 @@ func (c *Client) DeleteReleaseByTag(user, repo, tag string) (*Response, error) { return resp, err } -// fallbackGetReleaseByTag is fallback for old gitea installations ( < 1.13.0 ) +// fallbackGetReleaseByTag is fallback for old forgejo installations ( < 1.13.0 ) func (c *Client) fallbackGetReleaseByTag(owner, repo, tag string) (*Release, *Response, error) { for i := 1; ; i++ { rl, resp, err := c.ListReleases(owner, repo, ListReleasesOptions{ListOptions: ListOptions{Page: i}}) diff --git a/gitea/release_test.go b/forgejo/release_test.go similarity index 95% rename from gitea/release_test.go rename to forgejo/release_test.go index aa1d6f4..21579e9 100644 --- a/gitea/release_test.go +++ b/forgejo/release_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/repo.go b/forgejo/repo.go similarity index 98% rename from gitea/repo.go rename to forgejo/repo.go index 79aa52d..fb78d8f 100644 --- a/gitea/repo.go +++ b/forgejo/repo.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2014 The Gogs Authors. All rights reserved. // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" @@ -284,10 +288,10 @@ func (c *Client) SearchRepos(opt SearchRepoOptions) ([]*Repository, *Response, e link.RawQuery = opt.RawQuery } else { link.RawQuery = opt.QueryEncode() - // IsPrivate only works on gitea >= 1.12.0 + // IsPrivate only works on forgejo >= 1.12.0 if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil && opt.IsPrivate != nil { if *opt.IsPrivate { - // private repos only not supported on gitea <= 1.11.x + // private repos only not supported on forgejo <= 1.11.x return nil, nil, err } newQuery := link.Query() @@ -504,7 +508,7 @@ func (c *Client) GetRepoLanguages(owner, repo string) (map[string]int64, *Respon return langMap, resp, nil } -// ArchiveType represent supported archive formats by gitea +// ArchiveType represent supported archive formats by forgejo type ArchiveType string const ( diff --git a/gitea/repo_branch.go b/forgejo/repo_branch.go similarity index 96% rename from gitea/repo_branch.go rename to forgejo/repo_branch.go index 0b7e873..967c206 100644 --- a/gitea/repo_branch.go +++ b/forgejo/repo_branch.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2016 The Gogs Authors. All rights reserved. // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/repo_branch_protection.go b/forgejo/repo_branch_protection.go similarity index 97% rename from gitea/repo_branch_protection.go rename to forgejo/repo_branch_protection.go index 3196d03..3dc1d38 100644 --- a/gitea/repo_branch_protection.go +++ b/forgejo/repo_branch_protection.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/repo_branch_test.go b/forgejo/repo_branch_test.go similarity index 96% rename from gitea/repo_branch_test.go rename to forgejo/repo_branch_test.go index a0471e2..d16845b 100644 --- a/gitea/repo_branch_test.go +++ b/forgejo/repo_branch_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/repo_collaborator.go b/forgejo/repo_collaborator.go similarity index 96% rename from gitea/repo_collaborator.go rename to forgejo/repo_collaborator.go index 41e2576..e3ffe3d 100644 --- a/gitea/repo_collaborator.go +++ b/forgejo/repo_collaborator.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2021 The Gitea Authors. All rights reserved. // Copyright 2016 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/repo_collaborator_test.go b/forgejo/repo_collaborator_test.go similarity index 94% rename from gitea/repo_collaborator_test.go rename to forgejo/repo_collaborator_test.go index 5f5e2b4..069ed08 100644 --- a/gitea/repo_collaborator_test.go +++ b/forgejo/repo_collaborator_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2021 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/repo_commit.go b/forgejo/repo_commit.go similarity index 96% rename from gitea/repo_commit.go rename to forgejo/repo_commit.go index 62c0ab3..47c331d 100644 --- a/gitea/repo_commit.go +++ b/forgejo/repo_commit.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2018 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/repo_commit_test.go b/forgejo/repo_commit_test.go similarity index 92% rename from gitea/repo_commit_test.go rename to forgejo/repo_commit_test.go index 4369080..6a8889c 100644 --- a/gitea/repo_commit_test.go +++ b/forgejo/repo_commit_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "encoding/base64" diff --git a/gitea/repo_file.go b/forgejo/repo_file.go similarity index 97% rename from gitea/repo_file.go rename to forgejo/repo_file.go index 79bbeb1..4840f54 100644 --- a/gitea/repo_file.go +++ b/forgejo/repo_file.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2014 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" @@ -264,7 +268,7 @@ func (c *Client) DeleteFile(owner, repo, filepath string, opt DeleteFileOptions) func (c *Client) setDefaultBranchForOldVersions(owner, repo, branch string) (string, error) { if len(branch) == 0 { - // Gitea >= 1.12.0 Use DefaultBranch on "", mimic this for older versions + // Forgejo >= 1.12.0 Use DefaultBranch on "", mimic this for older versions if c.checkServerVersionGreaterThanOrEqual(version1_12_0) != nil { r, _, err := c.GetRepo(owner, repo) if err != nil { diff --git a/gitea/repo_file_test.go b/forgejo/repo_file_test.go similarity index 95% rename from gitea/repo_file_test.go rename to forgejo/repo_file_test.go index 32c0137..a866b47 100644 --- a/gitea/repo_file_test.go +++ b/forgejo/repo_file_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/repo_key.go b/forgejo/repo_key.go similarity index 94% rename from gitea/repo_key.go rename to forgejo/repo_key.go index ee2ff40..a70affe 100644 --- a/gitea/repo_key.go +++ b/forgejo/repo_key.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2015 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/repo_migrate.go b/forgejo/repo_migrate.go similarity index 85% rename from gitea/repo_migrate.go rename to forgejo/repo_migrate.go index 2de2153..5876a1f 100644 --- a/gitea/repo_migrate.go +++ b/forgejo/repo_migrate.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" @@ -20,6 +24,8 @@ const ( GitServiceGithub GitServiceType = "github" // GitServiceGitlab represents a gitlab service GitServiceGitlab GitServiceType = "gitlab" + // GitServiceForgejo represents a forgejo service + GitServiceForgejo GitServiceType = "forgejo" // GitServiceGitea represents a gitea service GitServiceGitea GitServiceType = "gitea" // GitServiceGogs represents a gogs service @@ -63,28 +69,28 @@ func (opt *MigrateRepoOption) Validate(c *Client) error { return fmt.Errorf("RepoName to long") } if len(opt.Description) > 2048 { - return fmt.Errorf("Description to long") + return fmt.Errorf("description to long") } switch opt.Service { case GitServiceGithub: if len(opt.AuthToken) == 0 { return fmt.Errorf("github requires token authentication") } - case GitServiceGitlab, GitServiceGitea: + case GitServiceGitlab, GitServiceGitea, GitServiceForgejo: if len(opt.AuthToken) == 0 { return fmt.Errorf("%s requires token authentication", opt.Service) } // Gitlab is supported since 1.12.0 but api cant handle it until 1.13.0 // https://github.com/go-gitea/gitea/pull/12672 if c.checkServerVersionGreaterThanOrEqual(version1_13_0) != nil { - return fmt.Errorf("migrate from service %s need gitea >= 1.13.0", opt.Service) + return fmt.Errorf("migrate from service %s need forgejo >= 1.13.0", opt.Service) } case GitServiceGogs: if len(opt.AuthToken) == 0 { return fmt.Errorf("gogs requires token authentication") } if c.checkServerVersionGreaterThanOrEqual(version1_14_0) != nil { - return fmt.Errorf("migrate from service gogs need gitea >= 1.14.0") + return fmt.Errorf("migrate from service gogs need forgejo >= 1.14.0") } } return nil @@ -101,19 +107,19 @@ func (c *Client) MigrateRepo(opt MigrateRepoOption) (*Repository, *Response, err if err := c.checkServerVersionGreaterThanOrEqual(version1_13_0); err != nil { if len(opt.AuthToken) != 0 { - // gitea <= 1.12 dont understand AuthToken + // forgejo <= 1.12 dont understand AuthToken opt.AuthUsername = opt.AuthToken opt.AuthPassword, opt.AuthToken = "", "" } if len(opt.RepoOwner) != 0 { - // gitea <= 1.12 dont understand RepoOwner + // forgejo <= 1.12 dont understand RepoOwner u, _, err := c.GetUserInfo(opt.RepoOwner) if err != nil { return nil, nil, err } opt.RepoOwnerID = u.ID } else if opt.RepoOwnerID == 0 { - // gitea <= 1.12 require RepoOwnerID + // forgejo <= 1.12 require RepoOwnerID u, _, err := c.GetMyUserInfo() if err != nil { return nil, nil, err diff --git a/gitea/repo_mirror.go b/forgejo/repo_mirror.go similarity index 88% rename from gitea/repo_mirror.go rename to forgejo/repo_mirror.go index df32094..abee87f 100644 --- a/gitea/repo_mirror.go +++ b/forgejo/repo_mirror.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2023 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/repo_refs.go b/forgejo/repo_refs.go similarity index 92% rename from gitea/repo_refs.go rename to forgejo/repo_refs.go index c954a80..b897a93 100644 --- a/gitea/repo_refs.go +++ b/forgejo/repo_refs.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2018 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "encoding/json" diff --git a/gitea/repo_stars.go b/forgejo/repo_stars.go similarity index 94% rename from gitea/repo_stars.go rename to forgejo/repo_stars.go index 01243c2..a35a3d3 100644 --- a/gitea/repo_stars.go +++ b/forgejo/repo_stars.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2021 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/repo_stars_test.go b/forgejo/repo_stars_test.go similarity index 91% rename from gitea/repo_stars_test.go rename to forgejo/repo_stars_test.go index d677e8c..dbb6f62 100644 --- a/gitea/repo_stars_test.go +++ b/forgejo/repo_stars_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2021 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/repo_tag.go b/forgejo/repo_tag.go similarity index 95% rename from gitea/repo_tag.go rename to forgejo/repo_tag.go index 7317d3f..aae0fe0 100644 --- a/gitea/repo_tag.go +++ b/forgejo/repo_tag.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/repo_tag_test.go b/forgejo/repo_tag_test.go similarity index 90% rename from gitea/repo_tag_test.go rename to forgejo/repo_tag_test.go index 6266531..1c84342 100644 --- a/gitea/repo_tag_test.go +++ b/forgejo/repo_tag_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/repo_team.go b/forgejo/repo_team.go similarity index 92% rename from gitea/repo_team.go rename to forgejo/repo_team.go index b983d87..ed7b9eb 100644 --- a/gitea/repo_team.go +++ b/forgejo/repo_team.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2021 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/repo_team_test.go b/forgejo/repo_team_test.go similarity index 92% rename from gitea/repo_team_test.go rename to forgejo/repo_team_test.go index b205a9f..0654468 100644 --- a/gitea/repo_team_test.go +++ b/forgejo/repo_team_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2021 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/repo_template.go b/forgejo/repo_template.go similarity index 92% rename from gitea/repo_template.go rename to forgejo/repo_template.go index 8b689be..546b88c 100644 --- a/gitea/repo_template.go +++ b/forgejo/repo_template.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2021 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/repo_template_test.go b/forgejo/repo_template_test.go similarity index 88% rename from gitea/repo_template_test.go rename to forgejo/repo_template_test.go index 3f8d891..314cf67 100644 --- a/gitea/repo_template_test.go +++ b/forgejo/repo_template_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2021 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/repo_test.go b/forgejo/repo_test.go similarity index 93% rename from gitea/repo_test.go rename to forgejo/repo_test.go index e6ddd14..cbf46bb 100644 --- a/gitea/repo_test.go +++ b/forgejo/repo_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" @@ -44,8 +48,9 @@ func TestRepoMigrateAndLanguages(t *testing.T) { _, _ = c.DeleteRepo(user.UserName, "sdk-mirror") } + // TODO: replace by proper url for forgejo repoM, _, err := c.MigrateRepo(MigrateRepoOption{ - CloneAddr: "https://gitea.com/gitea/go-sdk.git", + CloneAddr: "https://codeberg.org/mvdkleijn/forgejo-sdk.git", RepoName: "sdk-mirror", RepoOwner: user.UserName, Mirror: true, @@ -179,7 +184,7 @@ func createTestRepo(t *testing.T, name string, c *Client) (*Repository, error) { assert.NoError(t, uErr) repo, _, err := c.GetRepo(user.UserName, name) // We need to check that the received repo is not a - // redirected one, it could be the case that gitea redirect us + // redirected one, it could be the case that forgejo redirect us // to a new repo(because it e.g. was transferred or renamed). if err == nil && repo.Owner.UserName == user.UserName { _, _ = c.DeleteRepo(user.UserName, name) diff --git a/gitea/repo_topics.go b/forgejo/repo_topics.go similarity index 92% rename from gitea/repo_topics.go rename to forgejo/repo_topics.go index 92f2228..df6c29d 100644 --- a/gitea/repo_topics.go +++ b/forgejo/repo_topics.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/repo_topics_test.go b/forgejo/repo_topics_test.go similarity index 86% rename from gitea/repo_topics_test.go rename to forgejo/repo_topics_test.go index 837e4d7..c259235 100644 --- a/gitea/repo_topics_test.go +++ b/forgejo/repo_topics_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" @@ -23,7 +27,7 @@ func TestRepoTopics(t *testing.T) { assert.NoError(t, err) _, err = c.AddRepoTopic(repo.Owner.UserName, repo.Name, "git") assert.NoError(t, err) - _, err = c.AddRepoTopic(repo.Owner.UserName, repo.Name, "gitea") + _, err = c.AddRepoTopic(repo.Owner.UserName, repo.Name, "forgejo") assert.NoError(t, err) _, err = c.AddRepoTopic(repo.Owner.UserName, repo.Name, "drone") assert.NoError(t, err) diff --git a/gitea/repo_transfer.go b/forgejo/repo_transfer.go similarity index 92% rename from gitea/repo_transfer.go rename to forgejo/repo_transfer.go index 534a6e4..dd7f8e7 100644 --- a/gitea/repo_transfer.go +++ b/forgejo/repo_transfer.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/repo_transfer_test.go b/forgejo/repo_transfer_test.go similarity index 87% rename from gitea/repo_transfer_test.go rename to forgejo/repo_transfer_test.go index 7ec0694..514eff7 100644 --- a/gitea/repo_transfer_test.go +++ b/forgejo/repo_transfer_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/repo_tree.go b/forgejo/repo_tree.go similarity index 87% rename from gitea/repo_tree.go rename to forgejo/repo_tree.go index c9ffc55..a585a13 100644 --- a/gitea/repo_tree.go +++ b/forgejo/repo_tree.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2018 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/repo_watch.go b/forgejo/repo_watch.go similarity index 93% rename from gitea/repo_watch.go rename to forgejo/repo_watch.go index c36ca64..8a6713a 100644 --- a/gitea/repo_watch.go +++ b/forgejo/repo_watch.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2017 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/repo_watch_test.go b/forgejo/repo_watch_test.go similarity index 88% rename from gitea/repo_watch_test.go rename to forgejo/repo_watch_test.go index 8e74d7b..cdeb28b 100644 --- a/gitea/repo_watch_test.go +++ b/forgejo/repo_watch_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/secret.go b/forgejo/secret.go similarity index 64% rename from gitea/secret.go rename to forgejo/secret.go index 0f544a8..94054c2 100644 --- a/gitea/secret.go +++ b/forgejo/secret.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2023 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import "time" diff --git a/gitea/settings.go b/forgejo/settings.go similarity index 90% rename from gitea/settings.go rename to forgejo/settings.go index fb94248..9029a65 100644 --- a/gitea/settings.go +++ b/forgejo/settings.go @@ -1,17 +1,21 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo -// GlobalUISettings represent the global ui settings of a gitea instance witch is exposed by API +// GlobalUISettings represent the global ui settings of a forgejo instance witch is exposed by API type GlobalUISettings struct { DefaultTheme string `json:"default_theme"` AllowedReactions []string `json:"allowed_reactions"` CustomEmojis []string `json:"custom_emojis"` } -// GlobalRepoSettings represent the global repository settings of a gitea instance witch is exposed by API +// GlobalRepoSettings represent the global repository settings of a forgejo instance witch is exposed by API type GlobalRepoSettings struct { MirrorsDisabled bool `json:"mirrors_disabled"` HTTPGitDisabled bool `json:"http_git_disabled"` diff --git a/gitea/settings_test.go b/forgejo/settings_test.go similarity index 88% rename from gitea/settings_test.go rename to forgejo/settings_test.go index efcac76..018fd0f 100644 --- a/gitea/settings_test.go +++ b/forgejo/settings_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/status.go b/forgejo/status.go similarity index 94% rename from gitea/status.go rename to forgejo/status.go index fe5d971..26f2890 100644 --- a/gitea/status.go +++ b/forgejo/status.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2017 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" @@ -99,7 +103,7 @@ func (c *Client) GetCombinedStatus(owner, repo, ref string) (*CombinedStatus, *R status := new(CombinedStatus) resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/status", owner, repo, ref), jsonHeader, nil, status) - // gitea api return empty body if nothing here jet + // forgejo api return empty body if nothing here jet if resp != nil && resp.StatusCode == 200 && err != nil { return status, resp, nil } diff --git a/gitea/status_test.go b/forgejo/status_test.go similarity index 93% rename from gitea/status_test.go rename to forgejo/status_test.go index a1f78d5..f8f3fbe 100644 --- a/gitea/status_test.go +++ b/forgejo/status_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" diff --git a/gitea/user.go b/forgejo/user.go similarity index 93% rename from gitea/user.go rename to forgejo/user.go index 67208fb..c838c97 100644 --- a/gitea/user.go +++ b/forgejo/user.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2014 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/user_app.go b/forgejo/user_app.go similarity index 96% rename from gitea/user_app.go rename to forgejo/user_app.go index 92a3a26..35409cc 100644 --- a/gitea/user_app.go +++ b/forgejo/user_app.go @@ -1,9 +1,13 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2014 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/user_email.go b/forgejo/user_email.go similarity index 90% rename from gitea/user_email.go rename to forgejo/user_email.go index 4962b08..b8c9d9e 100644 --- a/gitea/user_email.go +++ b/forgejo/user_email.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2015 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/user_follow.go b/forgejo/user_follow.go similarity index 94% rename from gitea/user_follow.go rename to forgejo/user_follow.go index 7bd340c..79fa4c8 100644 --- a/gitea/user_follow.go +++ b/forgejo/user_follow.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2015 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import "fmt" diff --git a/gitea/user_gpgkey.go b/forgejo/user_gpgkey.go similarity index 94% rename from gitea/user_gpgkey.go rename to forgejo/user_gpgkey.go index 6c1b9d1..6bfd419 100644 --- a/gitea/user_gpgkey.go +++ b/forgejo/user_gpgkey.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2017 Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/user_key.go b/forgejo/user_key.go similarity index 93% rename from gitea/user_key.go rename to forgejo/user_key.go index 02795ba..65d2342 100644 --- a/gitea/user_key.go +++ b/forgejo/user_key.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2015 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/user_search.go b/forgejo/user_search.go similarity index 86% rename from gitea/user_search.go rename to forgejo/user_search.go index 5ea0c45..f0b6619 100644 --- a/gitea/user_search.go +++ b/forgejo/user_search.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" diff --git a/gitea/user_settings.go b/forgejo/user_settings.go similarity index 92% rename from gitea/user_settings.go rename to forgejo/user_settings.go index 494cab3..01480c9 100644 --- a/gitea/user_settings.go +++ b/forgejo/user_settings.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2021 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "bytes" diff --git a/gitea/user_settings_test.go b/forgejo/user_settings_test.go similarity index 81% rename from gitea/user_settings_test.go rename to forgejo/user_settings_test.go index 641089b..f1ff70f 100644 --- a/gitea/user_settings_test.go +++ b/forgejo/user_settings_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2021 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" @@ -19,7 +23,7 @@ func TestUserSettings(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, userConf) assert.EqualValues(t, UserSettings{ - Theme: "auto", + Theme: "forgejo-auto", HideEmail: false, HideActivity: false, }, *userConf) @@ -33,7 +37,7 @@ func TestUserSettings(t *testing.T) { assert.NotNil(t, userConf) assert.EqualValues(t, UserSettings{ FullName: "Admin User on Test", - Theme: "auto", + Theme: "forgejo-auto", Language: "de_de", HideEmail: true, HideActivity: false, diff --git a/gitea/user_test.go b/forgejo/user_test.go similarity index 89% rename from gitea/user_test.go rename to forgejo/user_test.go index 727fb1b..a766714 100644 --- a/gitea/user_test.go +++ b/forgejo/user_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" @@ -19,9 +23,9 @@ func TestMyUser(t *testing.T) { assert.EqualValues(t, 1, user.ID) assert.EqualValues(t, "test01", user.UserName) - assert.EqualValues(t, "test01@gitea.io", user.Email) + assert.EqualValues(t, "test01@forgejo.org", user.Email) assert.EqualValues(t, "", user.FullName) - assert.EqualValues(t, "https://secure.gravatar.com/avatar/d794373e882a68fb173cef817fb6180a?d=identicon", user.AvatarURL) + assert.EqualValues(t, "https://secure.gravatar.com/avatar/90e9f0102fc2832d69ae59a1214601c0?d=identicon", user.AvatarURL) assert.True(t, user.IsAdmin) } @@ -32,6 +36,7 @@ func TestUserApp(t *testing.T) { result, _, err := c.ListAccessTokens(ListAccessTokensOptions{}) assert.NoError(t, err) assert.Len(t, result, 1) + // the gitea-admin name for the token is hardcoded in forgejo itself, until it's changed this will need to do assert.EqualValues(t, "gitea-admin", result[0].Name) t1, _, err := c.CreateAccessToken(CreateAccessTokenOption{Name: "TestCreateAccessToken"}) @@ -144,7 +149,7 @@ func TestUserEmail(t *testing.T) { el, _, err := c.ListEmails(ListEmailsOptions{}) assert.NoError(t, err) assert.Len(t, el, 1) - assert.EqualValues(t, "testuseremail@gitea.io", el[0].Email) + assert.EqualValues(t, "testuseremail@forgejo.org", el[0].Email) assert.True(t, el[0].Primary) // AddEmail @@ -202,7 +207,7 @@ func createTestUser(t *testing.T, username string, client *Client) *User { if user.ID != 0 { return user } - user, _, err := client.AdminCreateUser(CreateUserOption{Username: username, Password: username + "!1234", Email: username + "@gitea.io", MustChangePassword: OptionalBool(false), SendNotify: false}) + user, _, err := client.AdminCreateUser(CreateUserOption{Username: username, Password: username + "!1234", Email: username + "@forgejo.org", MustChangePassword: OptionalBool(false), SendNotify: false}) assert.NoError(t, err) return user } diff --git a/gitea/version.go b/forgejo/version.go similarity index 83% rename from gitea/version.go rename to forgejo/version.go index e8df511..dc42117 100644 --- a/gitea/version.go +++ b/forgejo/version.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "fmt" @@ -35,15 +39,15 @@ func (c *Client) CheckServerVersionConstraint(constraint string) error { c.mutex.RLock() url := c.url c.mutex.RUnlock() - return fmt.Errorf("gitea server at %s does not satisfy version constraint %s", url, constraint) + return fmt.Errorf("forgejo server at %s does not satisfy version constraint %s", url, constraint) } return nil } -// SetGiteaVersion configures the Client to assume the given version of the -// Gitea server, instead of querying the server for it when initializing. +// SetForgejoVersion configures the Client to assume the given version of the +// Forgejo server, instead of querying the server for it when initializing. // Use "" to skip all canonical ways in the SDK to check for versions -func SetGiteaVersion(v string) ClientOption { +func SetForgejoVersion(v string) ClientOption { if v == "" { return func(c *Client) error { c.ignoreVersion = true @@ -81,7 +85,7 @@ func (e ErrUnknownVersion) Error() string { return fmt.Sprintf("unknown version: %s", e.raw) } -func (_ ErrUnknownVersion) Is(target error) bool { +func (ErrUnknownVersion) Is(target error) bool { _, ok1 := target.(*ErrUnknownVersion) _, ok2 := target.(ErrUnknownVersion) return ok1 || ok2 @@ -100,7 +104,7 @@ func (c *Client) checkServerVersionGreaterThanOrEqual(v *version.Version) error c.mutex.RLock() url := c.url c.mutex.RUnlock() - return fmt.Errorf("gitea server at %s is older than %s", url, v.Original()) + return fmt.Errorf("forgejo server at %s is older than %s", url, v.Original()) } return nil } diff --git a/gitea/version_test.go b/forgejo/version_test.go similarity index 76% rename from gitea/version_test.go rename to forgejo/version_test.go index 7383649..ea22653 100644 --- a/gitea/version_test.go +++ b/forgejo/version_test.go @@ -1,8 +1,12 @@ +// Copyright 2024 The Forgjo Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + // Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package gitea +package forgejo import ( "log" @@ -26,7 +30,7 @@ func TestVersion(t *testing.T) { c.ignoreVersion = true assert.NoError(t, c.checkServerVersionGreaterThanOrEqual(version1_15_0)) - c, err = NewClient(getGiteaURL(), newTestClientAuth(), SetGiteaVersion("1.12.123")) + c, err = NewClient(getForgejoURL(), newTestClientAuth(), SetForgejoVersion("1.12.123")) assert.NoError(t, err) assert.NoError(t, c.CheckServerVersionConstraint("=1.12.123")) } diff --git a/gitea/doc.go b/gitea/doc.go deleted file mode 100644 index 777ad2f..0000000 --- a/gitea/doc.go +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2016 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -// Package gitea implements a client for the Gitea API. -// The version corresponds to the highest supported version -// of the gitea API, but backwards-compatibility is mostly -// given. -package gitea // import "code.gitea.io/sdk/gitea" diff --git a/gitea/go.mod b/gitea/go.mod deleted file mode 100644 index 99e08ce..0000000 --- a/gitea/go.mod +++ /dev/null @@ -1,11 +0,0 @@ -module code.gitea.io/sdk/gitea - -go 1.13 - -require ( - github.com/davidmz/go-pageant v1.0.2 - github.com/go-fed/httpsig v1.1.0 - github.com/hashicorp/go-version v1.6.0 - github.com/stretchr/testify v1.7.0 - golang.org/x/crypto v0.17.0 -) diff --git a/gitea/main_test.go b/gitea/main_test.go deleted file mode 100644 index 40c81e5..0000000 --- a/gitea/main_test.go +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2020 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gitea - -import ( - "fmt" - "io" - "io/ioutil" - "log" - "net/http" - "os" - "os/exec" - "path/filepath" - "runtime" - "strconv" - "testing" -) - -func getGiteaURL() string { - return os.Getenv("GITEA_SDK_TEST_URL") -} - -func getGiteaToken() string { - return os.Getenv("GITEA_SDK_TEST_TOKEN") -} - -func getGiteaUsername() string { - return os.Getenv("GITEA_SDK_TEST_USERNAME") -} - -func getGiteaPassword() string { - return os.Getenv("GITEA_SDK_TEST_PASSWORD") -} - -func enableRunGitea() bool { - r, _ := strconv.ParseBool(os.Getenv("GITEA_SDK_TEST_RUN_GITEA")) - return r -} - -func newTestClient() *Client { - c, _ := NewClient(getGiteaURL(), newTestClientAuth()) - return c -} - -func newTestClientAuth() ClientOption { - token := getGiteaToken() - if token == "" { - return SetBasicAuth(getGiteaUsername(), getGiteaPassword()) - } - return SetToken(getGiteaToken()) -} - -func giteaMasterPath() string { - switch runtime.GOOS { - case "darwin": - return fmt.Sprintf("https://dl.gitea.io/gitea/master/gitea-master-darwin-10.6-%s", runtime.GOARCH) - case "linux": - return fmt.Sprintf("https://dl.gitea.io/gitea/master/gitea-master-linux-%s", runtime.GOARCH) - case "windows": - return fmt.Sprintf("https://dl.gitea.io/gitea/master/gitea-master-windows-4.0-%s.exe", runtime.GOARCH) - } - return "" -} - -func downGitea() (string, error) { - for i := 3; i > 0; i-- { - resp, err := http.Get(giteaMasterPath()) - if err != nil { - continue - } - defer resp.Body.Close() - - f, err := ioutil.TempFile(os.TempDir(), "gitea") - if err != nil { - continue - } - _, err = io.Copy(f, resp.Body) - f.Close() - if err != nil { - continue - } - - if err = os.Chmod(f.Name(), 0o700); err != nil { - return "", err - } - - return f.Name(), nil - } - - return "", fmt.Errorf("Download gitea from %v failed", giteaMasterPath()) -} - -func runGitea() (*os.Process, error) { - log.Println("Downloading Gitea from", giteaMasterPath()) - p, err := downGitea() - if err != nil { - log.Fatal(err) - } - - giteaDir := filepath.Dir(p) - cfgDir := filepath.Join(giteaDir, "custom", "conf") - err = os.MkdirAll(cfgDir, os.ModePerm) - if err != nil { - log.Fatal(err) - } - cfg, err := os.Create(filepath.Join(cfgDir, "app.ini")) - if err != nil { - log.Fatal(err) - } - - _, err = cfg.WriteString(`[security] -INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE1NTg4MzY4ODB9.LoKQyK5TN_0kMJFVHWUW0uDAyoGjDP6Mkup4ps2VJN4 -INSTALL_LOCK = true -SECRET_KEY = 2crAW4UANgvLipDS6U5obRcFosjSJHQANll6MNfX7P0G3se3fKcCwwK3szPyGcbo -[database] -DB_TYPE = sqlite3 -[log] -MODE = console -LEVEL = Trace -REDIRECT_MACARON_LOG = true -MACARON = , -ROUTER = ,`) - cfg.Close() - if err != nil { - log.Fatal(err) - } - - log.Println("Run gitea migrate", p) - err = exec.Command(p, "migrate").Run() - if err != nil { - log.Fatal(err) - } - - log.Println("Run gitea admin", p) - err = exec.Command(p, "admin", "create-user", "--username=test01", "--password=test01", "--email=test01@gitea.io", "--admin=true", "--must-change-password=false", "--access-token").Run() - if err != nil { - log.Fatal(err) - } - - log.Println("Start Gitea", p) - return os.StartProcess(filepath.Base(p), []string{}, &os.ProcAttr{ - Dir: giteaDir, - }) -} - -func TestMain(m *testing.M) { - if enableRunGitea() { - p, err := runGitea() - if err != nil { - log.Fatal(err) - return - } - defer func() { - if err := p.Kill(); err != nil { - log.Fatal(err) - } - }() - } - log.Printf("testing with %v, %v, %v\n", getGiteaURL(), getGiteaUsername(), getGiteaPassword()) - exitCode := m.Run() - os.Exit(exitCode) -}