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>
213 lines
5.8 KiB
Go
213 lines
5.8 KiB
Go
package gitlab
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// ReleasesService handles communication with the releases methods
|
|
// of the GitLab API.
|
|
//
|
|
// GitLab API docs: https://docs.gitlab.com/ce/api/releases/index.html
|
|
type ReleasesService struct {
|
|
client *Client
|
|
}
|
|
|
|
// Release represents a project release.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#list-releases
|
|
type Release struct {
|
|
TagName string `json:"tag_name"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description,omitempty"`
|
|
DescriptionHTML string `json:"description_html,omitempty"`
|
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
|
Author struct {
|
|
ID int `json:"id"`
|
|
Name string `json:"name"`
|
|
Username string `json:"username"`
|
|
State string `json:"state"`
|
|
AvatarURL string `json:"avatar_url"`
|
|
WebURL string `json:"web_url"`
|
|
} `json:"author"`
|
|
Commit Commit `json:"commit"`
|
|
Assets struct {
|
|
Count int `json:"count"`
|
|
Sources []struct {
|
|
Format string `json:"format"`
|
|
URL string `json:"url"`
|
|
} `json:"sources"`
|
|
Links []*ReleaseLink `json:"links"`
|
|
} `json:"assets"`
|
|
}
|
|
|
|
// ListReleasesOptions represents ListReleases() options.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#list-releases
|
|
type ListReleasesOptions ListOptions
|
|
|
|
// ListReleases gets a pagenated of releases accessible by the authenticated user.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#list-releases
|
|
func (s *ReleasesService) ListReleases(pid interface{}, opt *ListReleasesOptions, options ...OptionFunc) ([]*Release, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases", pathEscape(project))
|
|
|
|
req, err := s.client.NewRequest("GET", u, opt, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
var rs []*Release
|
|
resp, err := s.client.Do(req, &rs)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return rs, resp, err
|
|
}
|
|
|
|
// GetRelease returns a single release, identified by a tag name.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#get-a-release-by-a-tag-name
|
|
func (s *ReleasesService) GetRelease(pid interface{}, tagName string, options ...OptionFunc) (*Release, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases/%s", pathEscape(project), tagName)
|
|
|
|
req, err := s.client.NewRequest("GET", u, nil, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
r := new(Release)
|
|
resp, err := s.client.Do(req, r)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return r, resp, err
|
|
}
|
|
|
|
// ReleaseAssets represents release assets in CreateRelease() options
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#create-a-release
|
|
type ReleaseAssets struct {
|
|
Links []*ReleaseAssetLink `url:"links" json:"links"`
|
|
}
|
|
|
|
// ReleaseAssetLink represents release asset link in CreateRelease() options
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#create-a-release
|
|
type ReleaseAssetLink struct {
|
|
Name string `url:"name" json:"name"`
|
|
URL string `url:"url" json:"url"`
|
|
}
|
|
|
|
// CreateReleaseOptions represents CreateRelease() options.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#create-a-release
|
|
type CreateReleaseOptions struct {
|
|
Name *string `url:"name" json:"name"`
|
|
TagName *string `url:"tag_name" json:"tag_name"`
|
|
Description *string `url:"description" json:"description"`
|
|
Ref *string `url:"ref,omitempty" json:"ref,omitempty"`
|
|
Assets *ReleaseAssets `url:"assets,omitempty" json:"assets,omitempty"`
|
|
}
|
|
|
|
// CreateRelease creates a release.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#create-a-release
|
|
func (s *ReleasesService) CreateRelease(pid interface{}, opts *CreateReleaseOptions, options ...OptionFunc) (*Release, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases", pathEscape(project))
|
|
|
|
req, err := s.client.NewRequest("POST", u, opts, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
r := new(Release)
|
|
resp, err := s.client.Do(req, r)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return r, resp, err
|
|
}
|
|
|
|
// UpdateReleaseOptions represents UpdateRelease() options.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#update-a-release
|
|
type UpdateReleaseOptions struct {
|
|
Name *string `url:"name" json:"name"`
|
|
Description *string `url:"description" json:"description"`
|
|
}
|
|
|
|
// UpdateRelease updates a release.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#update-a-release
|
|
func (s *ReleasesService) UpdateRelease(pid interface{}, tagName string, opts *UpdateReleaseOptions, options ...OptionFunc) (*Release, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases/%s", pathEscape(project), tagName)
|
|
|
|
req, err := s.client.NewRequest("PUT", u, opts, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
r := new(Release)
|
|
resp, err := s.client.Do(req, &r)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return r, resp, err
|
|
}
|
|
|
|
// DeleteRelease deletes a release.
|
|
//
|
|
// GitLab API docs:
|
|
// https://docs.gitlab.com/ce/api/releases/index.html#delete-a-release
|
|
func (s *ReleasesService) DeleteRelease(pid interface{}, tagName string, options ...OptionFunc) (*Release, *Response, error) {
|
|
project, err := parseID(pid)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := fmt.Sprintf("projects/%s/releases/%s", pathEscape(project), tagName)
|
|
|
|
req, err := s.client.NewRequest("DELETE", u, nil, options)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
r := new(Release)
|
|
resp, err := s.client.Do(req, r)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return r, resp, err
|
|
}
|