feat: fork Gitea SDK (#1)

Reviewed-on: https://codeberg.org/mvdkleijn/forgejo-sdk/pulls/1
Co-authored-by: Martijn van der Kleijn <martijn.niji@gmail.com>
Co-committed-by: Martijn van der Kleijn <martijn.niji@gmail.com>
Signed-off-by: Martijn van der Kleijn <martijn.niji@gmail.com>
This commit is contained in:
Martijn van der Kleijn 2024-02-23 00:26:49 +00:00
parent 5d0143e4e7
commit 2e9e2fa7a3
114 changed files with 823 additions and 483 deletions

View file

@ -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:

View file

@ -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

View file

@ -1,8 +1,6 @@
<!--
1. Please speak English, this is the language all of us can speak and write.
2. Please ask questions or configuration/deploy problems on our Discord
server (https://discord.gg/NsatcWJ) or forum (https://discourse.gitea.io).
3. Please take a moment to check that your issue doesn't already exist.
4. Please give all relevant information below for bug reports, because
2. Please take a moment to check that your issue doesn't already exist.
3. Please give all relevant information below for bug reports, because
incomplete details will be handled as an invalid report.
-->

View file

@ -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.**

View file

@ -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 <joe.smith@email.com>
```
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) <xiaolunwen@gmail.com>
* [Thomas Boerger](https://github.com/tboerger) <thomas@webhippie.de>
* [Kim Carlbäcker](https://github.com/bkcsoft) <kim.carlbacker@gmail.com>
* 2018-01-01 ~ 2018-12-31
* [Lunny Xiao](https://gitea.com/lunny) <xiaolunwen@gmail.com>
* [Lauris Bukšis-Haberkorns](https://github.com/lafriks) <lauris@nix.lv>
* [Kim Carlbäcker](https://github.com/bkcsoft) <kim.carlbacker@gmail.com>
* 2019-01-01 ~ 2019-12-31
* [Lunny Xiao](https://gitea.com/lunny) <xiaolunwen@gmail.com>
* [Lauris Bukšis-Haberkorns](https://github.com/lafriks) <lauris@nix.lv>
* [Matti Ranta](https://github.com/techknowlogick) <matti@mdranta.net>
## 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.
```

View file

@ -1,3 +1,4 @@
Copyright (c) 2024 The Forgejo Authors
Copyright (c) 2016 The Gitea Authors
Copyright (c) 2014 The Gogs Authors

View file

@ -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

View file

@ -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.

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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 {

View file

@ -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{

13
forgejo/doc.go Normal file
View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

18
forgejo/go.mod Normal file
View file

@ -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
)

View file

@ -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=

View file

@ -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 {

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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())
}

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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)

View file

@ -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"

View file

@ -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.

168
forgejo/main_test.go Normal file
View file

@ -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)
}

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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
}

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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

View file

@ -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 == "" {

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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}})

View file

@ -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"

View file

@ -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 (

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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 {

View file

@ -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"

View file

@ -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"

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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)

View file

@ -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"

View file

@ -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)

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"`

View file

@ -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"

View file

@ -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
}

View file

@ -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"

View file

@ -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"

Some files were not shown because too many files have changed in this diff Show more