git_repositories.rb revision 8ec575832389c2588f0b5ca1f1dd2cc42d62eb12
fcfb528483369975066c6adf1c55c16e6fb6e91fTimo Sirainen "#{Ontohub::Application.config.git_root}/#{id}"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def save_file(tmp_file, filepath, message, user, iri=nil)
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen git.add_file({email: user[:email], name: user[:name]}, tmp_file, filepath, message) do |commit_oid|
fcfb528483369975066c6adf1c55c16e6fb6e91fTimo Sirainen # update existing ontology
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen version = o.versions.build({ :commit_oid => commit_oid, :user => user }, { without_protection: true })
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen clazz = filepath.ends_with?('.casl') ? DistributedOntology : SingleOntology
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen o.iri = iri || "http://#{Settings.hostname}/#{path}/#{Ontology.filename_without_extension(filepath)}"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen o.name = filepath.split('/')[-1].split(".")[0].capitalize
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen version = o.versions.build({ :commit_oid => commit_oid, :user => user }, { without_protection: true })
6a7f64562ddd0dd2fec755ec4e9c9afde8e85cf1Timo Sirainen return {type: :raw, file: file} if file
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen return {type: :dir, entries: list_folder(path, commit_oid)}
6a7f64562ddd0dd2fec755ec4e9c9afde8e85cf1Timo Sirainen entries = list_folder(path, commit_oid).select { |e| e[:name].split('.')[0] == file }
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen # given a commit oid or a branch name, commit_id returns a hash of oid and branch name if existent
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen return { oid: git.head_oid, branch_name: 'master' } if oid.nil?
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen if oid.match /[0-9a-fA-F]{40}/
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen branch_names = git.get_branches.select { |b| b[:oid] == oid }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen { oid: oid, branch_name: branch_names[0][:name] }