diff options
| author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-28 18:08:32 +0000 |
|---|---|---|
| committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-28 18:08:32 +0000 |
| commit | 36eff6e5089629619cc55f4771fa949d6ae2b29b (patch) | |
| tree | 6381b0c90f403c535abdde2f712cd346a78770fe /app/graphql/mutations/projects | |
| parent | baed745d21710f1d78ece03558873acd6fd7d358 (diff) | |
| download | gitlab-ce-36eff6e5089629619cc55f4771fa949d6ae2b29b.tar.gz | |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/graphql/mutations/projects')
| -rw-r--r-- | app/graphql/mutations/projects/sync_fork.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/app/graphql/mutations/projects/sync_fork.rb b/app/graphql/mutations/projects/sync_fork.rb new file mode 100644 index 00000000000..bb92f078fae --- /dev/null +++ b/app/graphql/mutations/projects/sync_fork.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +module Mutations + module Projects + class SyncFork < BaseMutation + graphql_name 'ProjectSyncFork' + + include FindsProject + + authorize :push_code + + argument :project_path, GraphQL::Types::ID, + required: true, + description: 'Full path of the project to initialize.' + + argument :target_branch, GraphQL::Types::String, + required: true, + description: 'Ref of the fork to fetch into.' + + field :details, Types::Projects::ForkDetailsType, + null: true, + description: 'Updated fork details.' + + def resolve(project_path:, target_branch:) + project = authorized_find!(project_path) + details_resolver = Resolvers::Projects::ForkDetailsResolver.new(object: project, context: context, field: nil) + details = details_resolver.resolve(ref: target_branch) + + return respond(nil, ['This branch of this project cannot be updated from the upstream']) unless details + + enqueue_sync_fork(project, target_branch, details) + end + + def enqueue_sync_fork(project, target_branch, details) + return respond(details, []) if details.counts[:behind] == 0 + + if details.has_conflicts? + return respond(details, ['The synchronization cannot happen due to the merge conflict']) + end + + return respond(details, ['This service has been called too many times.']) if rate_limit_throttled?(project) + return respond(details, ['Another fork sync is already in progress']) unless details.exclusive_lease.try_obtain + + ::Projects::Forks::SyncWorker.perform_async(project.id, current_user.id, target_branch) # rubocop:disable CodeReuse/Worker + + respond(details, []) + end + + def rate_limit_throttled?(project) + Gitlab::ApplicationRateLimiter.throttled?(:project_fork_sync, scope: [project, current_user]) + end + + def respond(details, errors) + { details: details, errors: errors } + end + end + end +end |
