Re: [gitorious] Create Project and Repository by script

2013-01-25 Thread Wilfried Kopp
Indeed, good news!!!
Thanks as well for the tips you gave me, they ended up very help ful.

In return, here are the scripts I am using today (they are worth what they
are :) they do the trick!). Warning hardcode insid to fetch some specific
users and groups, see 99 and 98:
#!/usr/local/bin/ruby
require File.dirname(__FILE__)+'/../config/environment'
require net/smtp

require 'optparse'

options = {}
OptionParser.new do |opts|
  # opts.banner = Usage: script.rb 

  opts.on(--email [EMAIL]) do |e|
options[:email] = e
  end

  opts.on(--title [TITLE]) do |t|
options[:title] = t
  end

  opts.on(--parentslug [SLUG]) do |s|
 options[:parentslug] = s
  end

  opts.on(--desc [DESCRIPTION]) do |d|
 options[:desc] = d
  end
end.parse!

p options
#p ARGV


# find email of the requester
u = User.find_by_email_with_aliases(options[:email])
wk = User.find(99)

# find id of git_admin group
gitadmin = Group.find(98)

# check if slug already exists: = will be done using SQL
# Project.all.select {|f| f[:slug] == p}

# find parent project:
proj = Project.find_by_sql(select * from projects where slug =
'#{options[:parentslug]}').first

repo = Repository.create!(
:name = options[:title],
:project = proj,
:description = options[:desc],
:owner = gitadmin,
:user = wk)

committership = repo.committerships.build(:creator = wk, :committer = u)
committership.build_permissions :commit, :admin
committership.save


p repo

---

#!/usr/local/bin/ruby
require File.dirname(__FILE__)+'/../config/environment'
require net/smtp

require 'optparse'

options = {}
OptionParser.new do |opts|
  # opts.banner = Usage: script.rb 

  #opts.on(--email [EMAIL]) do |e|
  #  options[:email] = e
  #end

  opts.on(--title [TITLE]) do |t|
options[:title] = t
  end

  opts.on(--slug [SLUG]) do |s|
 options[:slug] = s
  end

  opts.on(--desc [DESCRIPTION]) do |d|
 options[:desc] = d
  end
end.parse!

p options
#p ARGV


# find email of the requester
#u = User.find_by_email_with_aliases(options[:email])
wk = User.find(99)

# find id of git_admin group
gitadmin = Group.find(98)

# check if slug already exists: = will be done using SQL
# Project.all.select {|f| f[:slug] == p}

proj = Project.create!(
:title = options[:title],
:slug = options[:slug],
:description = options[:desc],
:owner = gitadmin,
:wiki_enabled = false,
:user = wk)

p proj

-



2013/1/23 Christian Johansen chrisj...@gmail.com

 Hi,

 It might please you that Gitorious will soon-ish have an HTTP Api for
 this.

 Until then, here are some clues to find your way around the console:

 * Use save! (with the exclamation mark) to get an exception that tells
   you what went wrong
 * You can see if a project is valid by doing p.valid?. If it's not
   valid, see what p.errors.inspect gives you

 Chrisitian

 chevdor writes:

  Hello,
 
  I am trying to find a solution to create new Projects and Respositories
 by
  script.
 
  So, from the console, I have tried:
 
  u = User.find(3)
  p=Project.create(:title = 'junk', :slug = 'junk', :description =
  'junk', :owner = u)
 
 
  This returns:
 
  = #Project id: nil, title: junk, description: junk, user_id: nil,
  created_at: nil, updated_at: nil, slug: junk, license: nil, home_url:
  nil, mailinglist_url: nil, bugtracker_url: nil, owner_id: 3, owner_type:
  User, wiki_enabled: true, site_id: nil, merge_requests_need_signoff:
  false, oauth_signoff_key: nil, oauth_signoff_secret: nil,
  oauth_signoff_site: nil, oauth_path_prefix: nil,
  merge_request_custom_states: nil, suspended_at: nil
 
 
  and p.save returns false.
  How is the 'id' generated?
 
  Is the method above the right one to create a new project?
 
  --

 --
 --
 To post to this group, send email to gitorious@googlegroups.com
 To unsubscribe from this group, send email to
 gitorious+unsubscr...@googlegroups.com






-- 
-- Wilfried Kopp   --
- chev...@gmail.com   -


-- 
-- 
To post to this group, send email to gitorious@googlegroups.com
To unsubscribe from this group, send email to
gitorious+unsubscr...@googlegroups.com





[gitorious] Create Project and Repository by script

2013-01-23 Thread chevdor
Hello,

I am trying to find a solution to create new Projects and Respositories by 
script.

So, from the console, I have tried:

 u = User.find(3)
 p=Project.create(:title = 'junk', :slug = 'junk', :description = 
 'junk', :owner = u)


This returns:

 = #Project id: nil, title: junk, description: junk, user_id: nil, 
 created_at: nil, updated_at: nil, slug: junk, license: nil, home_url: 
 nil, mailinglist_url: nil, bugtracker_url: nil, owner_id: 3, owner_type: 
 User, wiki_enabled: true, site_id: nil, merge_requests_need_signoff: 
 false, oauth_signoff_key: nil, oauth_signoff_secret: nil, 
 oauth_signoff_site: nil, oauth_path_prefix: nil, 
 merge_request_custom_states: nil, suspended_at: nil


and p.save returns false.
How is the 'id' generated?

Is the method above the right one to create a new project?

-- 
-- 
To post to this group, send email to gitorious@googlegroups.com
To unsubscribe from this group, send email to
gitorious+unsubscr...@googlegroups.com





Re: [gitorious] Create Project and Repository by script

2013-01-23 Thread Christian Johansen
Hi,

It might please you that Gitorious will soon-ish have an HTTP Api for
this.

Until then, here are some clues to find your way around the console:

* Use save! (with the exclamation mark) to get an exception that tells
  you what went wrong
* You can see if a project is valid by doing p.valid?. If it's not
  valid, see what p.errors.inspect gives you

Chrisitian

chevdor writes:

 Hello,

 I am trying to find a solution to create new Projects and Respositories by
 script.

 So, from the console, I have tried:

 u = User.find(3)
 p=Project.create(:title = 'junk', :slug = 'junk', :description =
 'junk', :owner = u)


 This returns:

 = #Project id: nil, title: junk, description: junk, user_id: nil,
 created_at: nil, updated_at: nil, slug: junk, license: nil, home_url:
 nil, mailinglist_url: nil, bugtracker_url: nil, owner_id: 3, owner_type:
 User, wiki_enabled: true, site_id: nil, merge_requests_need_signoff:
 false, oauth_signoff_key: nil, oauth_signoff_secret: nil,
 oauth_signoff_site: nil, oauth_path_prefix: nil,
 merge_request_custom_states: nil, suspended_at: nil


 and p.save returns false.
 How is the 'id' generated?

 Is the method above the right one to create a new project?

 --

-- 
-- 
To post to this group, send email to gitorious@googlegroups.com
To unsubscribe from this group, send email to
gitorious+unsubscr...@googlegroups.com