用github api重命名文件?

时间:2015-07-22 12:39:40

标签: rename github-api

我认为Github API的update file方法可用于重命名文件(通过提供新路径作为参数),但它似乎不起作用。

重命名的唯一方法是删除文件并使用新名称创建类似文件?

2 个答案:

答案 0 :(得分:2)

  

我认为Github API的更新文件方法可用于重命名文件(通过提供新路径作为参数)但它似乎不起作用。

无法通过向API发出单个请求来重命名文件。

  

重命名的唯一方法是删除文件并使用新名称创建类似文件?

这是单向的,但缺点是您在历史记录中有两个提交(一个用于删除,一个用于创建)。

另一种方法是使用低级Git API:

https://developer.github.com/v3/git/

这样,您可以修改包含blob的树条目以在不同的名称下列出它,然后为该树创建新的提交,最后更新分支以指向新的提交。整个过程需要更多的API请求,但您只需重命名一次提交。

答案 1 :(得分:0)

借助以下文章,我了解了如何使用Github API重命名文件。

首先,找到并存储最近提交的树。

Rails.application.routes.draw do
  root 'messages#index'
  resources :users
  resources :messages
  get    '/login',   to: 'sessions#new'
  post   '/login',   to: 'sessions#create'
  delete '/logout',  to: 'sessions#destroy'

  mount ActionCable.server, at: '/cable'
end 

使用使用困难的方式中所述的文件 GitHub API 来创建新树。然后,像 nodeJs版本会这样做,并基于以下更改创建新树。

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    include SessionsHelper

    identified_by :message_user

    def connect
      self.message_user = find_verified_user
    end

    private

      def find_verified_user
        if logged_in?
          current_user
        else
          reject_unauthorized_connection
        end
      end
  end
end

创建一个新的提交,然后将HEAD指向它。

Error: Existing connection must be closed before opening action_cable.self-17ebe4af84895fa064a951f57476799066237d7bb5dc4dc351a8b01cca19cce9.js:231:19
Connection.prototype.open
http://localhost:3000/assets/action_cable.self-17ebe4af84895fa064a951f57476799066237d7bb5dc4dc351a8b01cca19cce9.js:231:19
bind/<
http://localhost:3000/assets/action_cable.self-17ebe4af84895fa064a951f57476799066237d7bb5dc4dc351a8b01cca19cce9.js:201:60

仅此而已。