diff --git a/pagure/forms.py b/pagure/forms.py
index f2f83d3..2aae91c 100644
--- a/pagure/forms.py
+++ b/pagure/forms.py
@@ -49,6 +49,10 @@ class ProjectForm(ProjectFormSimplified):
wtforms.validators.Regexp(PROJECT_NAME_REGEX, flags=re.IGNORECASE)
]
)
+ create_readme = wtforms.BooleanField(
+ 'Create README',
+ [wtforms.validators.optional()],
+ )
class IssueFormSimplied(wtf.Form):
diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py
index 89c3a21..c998f7d 100644
--- a/pagure/lib/__init__.py
+++ b/pagure/lib/__init__.py
@@ -963,7 +963,7 @@ def add_pull_request_flag(session, request, username, percent, comment, url,
def new_project(session, user, name, blacklist, allowed_prefix,
gitfolder, docfolder, ticketfolder, requestfolder,
description=None, url=None, avatar_email=None,
- parent_id=None):
+ parent_id=None, add_readme=False, userobj=None):
''' Create a new project based on the information provided.
'''
if name in blacklist:
@@ -1013,7 +1013,22 @@ def new_project(session, user, name, blacklist, allowed_prefix,
# Make sure we won't have SQLAlchemy error before we create the repo
session.commit()
- pygit2.init_repository(gitrepo, bare=True)
+ if not add_readme:
+ pygit2.init_repository(gitrepo, bare=True)
+ else:
+ temp_gitrepo_path = os.path.join(gitfolder, '%s' % name)
+ temp_gitrepo = pygit2.init_repository(temp_gitrepo_path, bare=False)
+ author = pygit2.Signature(userobj.fullname, userobj.default_email)
+ f = open(os.path.join(temp_gitrepo.workdir,"README.md"), 'w')
+ f.write("# %s\n\n%s" % (name, description))
+ f.close()
+ temp_gitrepo.index.add_all()
+ temp_gitrepo.index.write()
+ tree = temp_gitrepo.index.write_tree()
+ temp_gitrepo.create_commit('HEAD', author,author, 'Added the README', tree, [])
+ pygit2.clone_repository(temp_gitrepo_path, gitrepo, bare=True)
+ shutil.rmtree(temp_gitrepo_path)
+
http_clone_file = os.path.join(gitrepo, 'git-daemon-export-ok')
if not os.path.exists(http_clone_file):
with open(http_clone_file, 'w') as stream:
diff --git a/pagure/templates/new_project.html b/pagure/templates/new_project.html
index 3a99e99..cf9a920 100644
--- a/pagure/templates/new_project.html
+++ b/pagure/templates/new_project.html
@@ -19,6 +19,7 @@
{{ render_bootstrap_field(form.description, field_description="short description of the project") }}
{{ render_bootstrap_field(form.url, field_description="url of the project's website") }}
{{ render_bootstrap_field(form.avatar_email, field_description="libravatar email address avatar email") }}
+ {{ render_bootstrap_field(form.create_readme, field_description="Create a README file automatically") }}
{{ form.csrf_token }}
diff --git a/pagure/ui/app.py b/pagure/ui/app.py
index 00b4b1a..71877a2 100644
--- a/pagure/ui/app.py
+++ b/pagure/ui/app.py
@@ -361,6 +361,8 @@ def view_user_requests(username):
def new_project():
""" Form to create a new project.
"""
+ user = pagure.lib.search_user(SESSION, username=flask.g.fas_user.username)
+
if not pagure.APP.config.get('ENABLE_NEW_PROJECTS', True):
flask.abort(404)
@@ -370,6 +372,7 @@ def new_project():
description = form.description.data
url = form.url.data
avatar_email = form.avatar_email.data
+ create_readme = form.create_readme.data
try:
message = pagure.lib.new_project(
@@ -385,6 +388,8 @@ def new_project():
docfolder=APP.config['DOCS_FOLDER'],
ticketfolder=APP.config['TICKETS_FOLDER'],
requestfolder=APP.config['REQUESTS_FOLDER'],
+ add_readme=create_readme,
+ userobj=user,
)
SESSION.commit()
pagure.lib.git.generate_gitolite_acls()