You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

null_downloader.go 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package base
  5. import (
  6. "context"
  7. "net/url"
  8. )
  9. // NullDownloader implements a blank downloader
  10. type NullDownloader struct {
  11. }
  12. var (
  13. _ Downloader = &NullDownloader{}
  14. )
  15. // SetContext set context
  16. func (n NullDownloader) SetContext(_ context.Context) {}
  17. // GetRepoInfo returns a repository information
  18. func (n NullDownloader) GetRepoInfo() (*Repository, error) {
  19. return nil, &ErrNotSupported{Entity: "RepoInfo"}
  20. }
  21. // GetTopics return repository topics
  22. func (n NullDownloader) GetTopics() ([]string, error) {
  23. return nil, &ErrNotSupported{Entity: "Topics"}
  24. }
  25. // GetMilestones returns milestones
  26. func (n NullDownloader) GetMilestones() ([]*Milestone, error) {
  27. return nil, &ErrNotSupported{Entity: "Milestones"}
  28. }
  29. // GetReleases returns releases
  30. func (n NullDownloader) GetReleases() ([]*Release, error) {
  31. return nil, &ErrNotSupported{Entity: "Releases"}
  32. }
  33. // GetLabels returns labels
  34. func (n NullDownloader) GetLabels() ([]*Label, error) {
  35. return nil, &ErrNotSupported{Entity: "Labels"}
  36. }
  37. // GetIssues returns issues according start and limit
  38. func (n NullDownloader) GetIssues(page, perPage int) ([]*Issue, bool, error) {
  39. return nil, false, &ErrNotSupported{Entity: "Issues"}
  40. }
  41. // GetComments returns comments according the options
  42. func (n NullDownloader) GetComments(GetCommentOptions) ([]*Comment, bool, error) {
  43. return nil, false, &ErrNotSupported{Entity: "Comments"}
  44. }
  45. // GetPullRequests returns pull requests according page and perPage
  46. func (n NullDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bool, error) {
  47. return nil, false, &ErrNotSupported{Entity: "PullRequests"}
  48. }
  49. // GetReviews returns pull requests review
  50. func (n NullDownloader) GetReviews(pullRequestContext IssueContext) ([]*Review, error) {
  51. return nil, &ErrNotSupported{Entity: "Reviews"}
  52. }
  53. // FormatCloneURL add authentification into remote URLs
  54. func (n NullDownloader) FormatCloneURL(opts MigrateOptions, remoteAddr string) (string, error) {
  55. if len(opts.AuthToken) > 0 || len(opts.AuthUsername) > 0 {
  56. u, err := url.Parse(remoteAddr)
  57. if err != nil {
  58. return "", err
  59. }
  60. u.User = url.UserPassword(opts.AuthUsername, opts.AuthPassword)
  61. if len(opts.AuthToken) > 0 {
  62. u.User = url.UserPassword("oauth2", opts.AuthToken)
  63. }
  64. return u.String(), nil
  65. }
  66. return remoteAddr, nil
  67. }
  68. // SupportGetRepoComments return true if it supports get repo comments
  69. func (n NullDownloader) SupportGetRepoComments() bool {
  70. return false
  71. }