gitea源码

null_downloader.go 2.7KB

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