1

我有一个 API,我希望 nuget 包使用我自己的提要进行更新,但是当我进入这个 UpdateCheckers 设置时,它显示我 update_not_possible。该项目就像nugets feed一样托管在azure上,执行构建时,它只执行而不创建拉取请求,se only in Found # {dep.name} @ # {dep.version} ...

 require "dependabot/file_fetchers"
 require "dependabot/file_parsers"
 require "dependabot/update_checkers"
 require "dependabot/file_updaters"
 require "dependabot/pull_request_creator"
 require "dependabot/pull_request_updater"
 require "dependabot/omnibus"
 
 package_manager = "nuget"
 repo_name = "/myproject/_git/WebApi.Dummy"

 directory = "src/WebApi.Dummy" 
 branch= "Dependabot"
 azure_hostname = "https://dev.azure.com/myorganization/myproject" || "dev.azure.com"
 
 
 credentials = [{
   "type" => "git_source",
   "host" => azure_hostname,
   "username" => "x-access-token",
   "password" => "my_personal_token"
 },{
   "type" => "nuget_feed",
   "url" => "https://dev.azure.com/myorganization/myproject/_packaging/myfeedNuget/nuget/v3/index.json",
   "token" => ":my_personal_token"
 }
 ]

 source = Dependabot::Source.new(
   provider: "azure",
   hostname: azure_hostname,
   api_endpoint: "http://#{azure_hostname}/",
   repo: repo_name,
   directory: directory,
   branch: branch
 )
 
 puts "Fetching #{package_manager} dependency files for #{repo_name}"
 fetcher = Dependabot::FileFetchers.for_package_manager(package_manager).new(
   source: source,
   credentials: credentials,
 )
 
 files = fetcher.files
 commit = fetcher.commit 

 parser = Dependabot::FileParsers.for_package_manager(package_manager).new(
   dependency_files: files,
   source: source,
   credentials: credentials,
 )
 
 dependencies = parser.parse
 
 dependencies.select(&:top_level?).each do |dep|
   puts "Found #{dep.name} @ #{dep.version}..."
 
   checker = Dependabot::UpdateCheckers.for_package_manager(package_manager).new(
     dependency: dep,
     dependency_files: files,
     credentials: credentials,
   )
 
   if checker.up_to_date?
    puts "  already using latest version"
    next
   end
 
   requirements_to_unlock =
     if !checker.requirements_unlocked_or_can_be?
       if checker.can_update?(requirements_to_unlock: :none) then :none
       else :update_not_possible
       end
     elsif checker.can_update?(requirements_to_unlock: :own) then :own
     elsif checker.can_update?(requirements_to_unlock: :all) then :all
     else :update_not_possible
     end
 
   next if requirements_to_unlock == :update_not_possible
 
   updated_deps = checker.updated_dependencies(
     requirements_to_unlock: requirements_to_unlock
   )
 
   puts "  considering upgrade to #{checker.latest_version}"
 
   updater = Dependabot::FileUpdaters.for_package_manager(package_manager).new(
     dependencies: updated_deps,
     dependency_files: files,
     credentials: credentials,
   )
 
   updated_files = updater.updated_dependency_files
 
 
   pr_creator = Dependabot::PullRequestCreator.new(
     source: source,
     base_commit: commit,
     dependencies: updated_deps,
     files: updated_files,
     credentials: credentials,
     label_language: true,
     author_details: {
       email: "dependabot@bccr.fi.cr",
       name: "dependabot"
     },
   )
   pull_request = pr_creator.create
 
   if pull_request&.status == 201
     content = JSON[pull_request.body]
     puts "  PR ##{content["pullRequestId"]} submitted"
     ENV['PR_ID']="##{content["pullRequestId"]}"
   else
     puts "  PR already exists or an error has occurred"
   end
 
   next unless pull_request
 end
 puts "Done"
4

0 回答 0