#-- # Git Repository Metafile Helper # # Copyright (C) 2010 Tero Hanninen # # This helper is used for updating repositories' metainformation: # adding/updating metafiles in repos and updating metainfo in the database. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . #++ module GrmfHelper require "yaml" require "fileutils" # Reads metainfo from repository and updates that info to database def update_metainfo_to_database(repo) path = full_path(repo.hashed_path) rep = Grit::Repo.new(path) blob = rep.tree(meta_branch_name)/'repository.yml' obj = YAML::load(blob.data) name = obj["name"] merge_requests_enabled = obj["merge_request_enabled"] blob2 = rep.tree(meta_branch_name)/'description' repo.description = blob2.data repo.name = name repo.merge_requests_enabled = merge_requests_enabled repo.save! end # Updates metafiles into repo from given repo object def update_metainfo_to_repository(repo_obj) path = full_path(repo_obj.hashed_path) repo = Grit::Repo.new(path) index = repo.index #author = repo_obj.owner.login #if repo_obj.owner.fullname != nil then author = repo_obj.owner.fullname end content = to_yaml_obj({ "name" => repo_obj.name, "merge_requests_enabled" => repo_obj.merge_requests_enabled }) # "author" => author }) index.add('repository.yml', content) index.add('description', repo_obj.description) parents = [repo.commits(meta_branch_name, 1, 0).first] actor = Grit::Actor.new("yousource","nomail") last_tree = nil #index.read_tree(repo.tree(meta_branch_name).id) index.commit("Update metafiles.", parents, actor, last_tree, meta_branch_name) end def meta_branch_name GitoriousConfig['repo_meta_branch'] end def full_path(repo_hashed_path) File.join(GitoriousConfig['repository_base_path'], "#{repo_hashed_path}.git") end # Returns any given ruby-object as a yaml-object which is a string. def to_yaml_obj(obj) YAML::dump(obj) end end