github.rb
# This method creates a branch on the papers_repo for the issue.
# -- First it looks for files in the current branch
# -- If it finds any, it deletes them.
# -- Deletes the branch. Then recreates it.
# -- If it doesn't find a branch for that issue. It simply creates one.
This method creates a branch on the papers_repo for the issue.
First it looks for files in the current branch
If it finds any, it deletes them.
Deletes the branch. Then recreates it.
If it doesn't find a branch for that issue. It simply creates one.
This method creates a branch on the papers_repo for the issue . First it looks for files in the current branch If it finds any it deletes them . Deletes the branch . Then recreates it . If it doesn ' t find a branch for that issue . It simply creates one .
def create_or_update_git_branch(issue_id, papers_repo, journal_alias)
    id = "%05d" % issue_id
    branch = "#{journal_alias}.#{id}"
    ref = "heads/#{branch}"
    begin
      files = github_client.contents(papers_repo,
                                     :path => branch,
                                     :ref => ref)
      files.each do |file|
        github_client.delete_contents(papers_repo,
                                      file.path,
                                      "Deleting #{file.name}",
                                      file.sha,
                                      :branch => branch)
      end
      github_client.delete_ref(papers_repo, "heads/#{journal_alias}.#{id}")
      github_client.create_ref(papers_repo, "heads/#{journal_alias}.#{id}", get_master_ref(papers_repo))
    rescue Octokit::NotFound 
      begin
        github_client.create_ref(papers_repo, "heads/#{journal_alias}.#{id}", get_master_ref(papers_repo))
      rescue Octokit::UnprocessableEntity
      end
    end
  end
def create_or_update_git_branch ( issue_id , papers_repo , journal_alias ) id = "%05d" % issue_id branch = "#{journal_alias}.#{id}" ref = "heads/#{branch}" begin files = github_client . contents ( papers_repo , :path => branch , :ref => ref ) files . each do | file | github_client . delete_contents ( papers_repo , file . path , "Deleting #{file.name}" , file . sha , :branch => branch ) end github_client . delete_ref ( papers_repo , "heads/#{journal_alias}.#{id}" ) github_client . create_ref ( papers_repo , "heads/#{journal_alias}.#{id}" , get_master_ref ( papers_repo ) ) rescue Octokit :: NotFound begin github_client . create_ref ( papers_repo , "heads/#{journal_alias}.#{id}" , get_master_ref ( papers_repo ) ) rescue Octokit :: UnprocessableEntity end end end
This method creates a branch on the papers_repo for the issue.
This method creates a branch on the papers_repo for the issue .
# First grab the files in this branch # Delete the old branch # Then create it again # If the branch doesn't exist, or there aren't any commits in the branch then create it! # If the branch already exists move on...
issue_id
papers_repo
journal_alias