mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 08:57:03 -05:00
5c092eb0ef
* First stab at a Gitlab migrations interface. * Modify JS to show migration for Gitlab * Properly strip out #gitlab tag from repo name * Working Gitlab migrations! Still need to figure out how to hide tokens/etc from showing up in opts.CloneAddr * Try #2 at trying to hide credentials. CloneAddr was being used as OriginalURL. Now passing OriginalURL through from the form and saving it. * Add go-gitlab dependency * Vendor go-gitlab * Use gitlab.BasicAuthClient Correct CloneURL. This should be functioning! Previous commits fixed "Migrated from" from including the migration credentials. * Replaced repoPath with repoID globally. RepoID is grabbed in NewGitlabDownloader * Logging touchup * Properly set private repo status. Properly set milestone deadline time. Consistently use Gitlab username for 'Name'. * Add go-gitlab vendor cache * Fix PR migrations: - Count of issues is kept to set a non-conflicting PR.ID - Bool is used to tell whether to fetch Issue or PR comments * Ensure merged PRs are closed and set with the proper time * Remove copyright and some commented code * Rip out '#gitlab' based self-hosted Gitlab support * Hide given credentials for migrated repos. CloneAddr was being saved as OriginalURL. Now passing OriginalURL through from the form and saving it in it's place * Use asset.URL directly, no point in parsing. Opened PRs should fall through to false. * Fix importing Milestones. Allow importing using Personal Tokens or anonymous access. * Fix Gitlab Milestone migration if DueDate isn't set * Empty Milestone due dates properly return nil, not zero time * Add GITLAB_READ_TOKEN to drone unit-test step * Add working gitlab_test.go. A Personal Access Token, given in env variable GITLAB_READ_TOKEN is required to run the test. * Fix linting issues * Add modified JS files * Remove pre-build JS files * Only merged PRs are marged as merged/closed * Test topics * Skip test if gitlab is inaccessible * Grab personal token from username, not password. Matches Github migration implementation * Add SetContext() to GitlabDownloader. * Checking Updated field in Issues. * Actually fetch Issue Updated time from Gitlab * Add Gitlab migration GetReviews() stub * Fix Patch and Clone URLs * check Updated too * fix mod * make vendor with go1.14 Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
176 lines
4.8 KiB
Go
176 lines
4.8 KiB
Go
package gitlab
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// ReleaseLinksService handles communication with the release link methods
|
|
// of the GitLab API.
|
|
//
|
|
// GitLab API docs: https://docs.gitlab.com/ee/api/releases/links.html
|
|
type ReleaseLinksService struct {
|
|
client *Client
|
|
}
|
|
|
|
// ReleaseLink represents a release link.
|
|
//
|
|
// GitLab API docs: https://docs.gitlab.com/ee/api/releases/links.html
|
|
type ReleaseLink struct {
|
|
ID int `json:"id"`
|
|
Name string `json:"name"`
|
|
URL string `json:"url"`
|
|
External bool `json:"external"`
|
|
}
|
|
|
|
// ListReleaseLinksOptions represents ListReleaseLinks() options.
|
|
//
|
|
// GitLab API docs: https://docs.gitlab.com/ee/api/releases/links.html#get-links
|
|
type ListReleaseLinksOptions ListOptions
|
|
|
|
// ListReleaseLinks gets assets as links from a Release.
|
|
//
|
|
// GitLab API docs: https://docs.gitlab.com/ee/api/releases/links.html#get-links
|
|
func (s *ReleaseLinksService) ListReleaseLinks(pid interface{}, tagName string, opt *ListReleaseLinksOptions, options ...OptionFunc) ([]*ReleaseLink, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases/%s/assets/links", pathEscape(project), tagName)
|
|
|
|
req, err := s.client.NewRequest("GET", u, opt, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
var rls []*ReleaseLink
|
|
resp, err := s.client.Do(req, &rls)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return rls, resp, err
|
|
}
|
|
|
|
// GetReleaseLink returns a link from release assets.
|
|
//
|
|
// GitLab API docs: https://docs.gitlab.com/ee/api/releases/links.html#get-a-link
|
|
func (s *ReleaseLinksService) GetReleaseLink(pid interface{}, tagName string, link int, options ...OptionFunc) (*ReleaseLink, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases/%s/assets/links/%d",
|
|
pathEscape(project),
|
|
tagName,
|
|
link)
|
|
|
|
req, err := s.client.NewRequest("GET", u, nil, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
rl := new(ReleaseLink)
|
|
resp, err := s.client.Do(req, rl)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return rl, resp, err
|
|
}
|
|
|
|
// CreateReleaseLinkOptions represents CreateReleaseLink() options.
|
|
//
|
|
// GitLab API docs: https://docs.gitlab.com/ee/api/releases/links.html#create-a-link
|
|
type CreateReleaseLinkOptions struct {
|
|
Name *string `url:"name" json:"name"`
|
|
URL *string `url:"url" json:"url"`
|
|
}
|
|
|
|
// CreateReleaseLink creates a link.
|
|
//
|
|
// GitLab API docs: https://docs.gitlab.com/ee/api/releases/links.html#create-a-link
|
|
func (s *ReleaseLinksService) CreateReleaseLink(pid interface{}, tagName string, opt *CreateReleaseLinkOptions, options ...OptionFunc) (*ReleaseLink, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases/%s/assets/links", pathEscape(project), tagName)
|
|
|
|
req, err := s.client.NewRequest("POST", u, opt, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
rl := new(ReleaseLink)
|
|
resp, err := s.client.Do(req, rl)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return rl, resp, err
|
|
}
|
|
|
|
// UpdateReleaseLinkOptions represents UpdateReleaseLink() options.
|
|
//
|
|
// You have to specify at least one of Name of URL.
|
|
//
|
|
// GitLab API docs: https://docs.gitlab.com/ee/api/releases/links.html#update-a-link
|
|
type UpdateReleaseLinkOptions struct {
|
|
Name *string `url:"name,omitempty" json:"name,omitempty"`
|
|
URL *string `url:"url,omitempty" json:"url,omitempty"`
|
|
}
|
|
|
|
// UpdateReleaseLink updates an asset link.
|
|
//
|
|
// GitLab API docs: https://docs.gitlab.com/ee/api/releases/links.html#update-a-link
|
|
func (s *ReleaseLinksService) UpdateReleaseLink(pid interface{}, tagName string, link int, opt *UpdateReleaseLinkOptions, options ...OptionFunc) (*ReleaseLink, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases/%s/assets/links/%d",
|
|
pathEscape(project),
|
|
tagName,
|
|
link)
|
|
|
|
req, err := s.client.NewRequest("PUT", u, opt, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
rl := new(ReleaseLink)
|
|
resp, err := s.client.Do(req, rl)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return rl, resp, err
|
|
}
|
|
|
|
// DeleteReleaseLink deletes a link from release.
|
|
//
|
|
// GitLab API docs: https://docs.gitlab.com/ee/api/releases/links.html#delete-a-link
|
|
func (s *ReleaseLinksService) DeleteReleaseLink(pid interface{}, tagName string, link int, options ...OptionFunc) (*ReleaseLink, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases/%s/assets/links/%d",
|
|
pathEscape(project),
|
|
tagName,
|
|
link,
|
|
)
|
|
|
|
req, err := s.client.NewRequest("DELETE", u, nil, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
rl := new(ReleaseLink)
|
|
resp, err := s.client.Do(req, rl)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return rl, resp, err
|
|
}
|