mirror of
https://github.com/YunoHost/apps.git
synced 2024-09-03 20:06:07 +02:00
appstore: fix add-to-wishlist PR mechanism after tests on the battlefield
This commit is contained in:
parent
1995213f52
commit
2721f8ae63
2 changed files with 28 additions and 11 deletions
28
store/app.py
28
store/app.py
|
@ -1,3 +1,4 @@
|
||||||
|
import time
|
||||||
import re
|
import re
|
||||||
import toml
|
import toml
|
||||||
import base64
|
import base64
|
||||||
|
@ -133,7 +134,7 @@ def add_to_wishlist():
|
||||||
user = session.get('user', {})
|
user = session.get('user', {})
|
||||||
if not user:
|
if not user:
|
||||||
errormsg = "You must be logged in to submit an app to the wishlist"
|
errormsg = "You must be logged in to submit an app to the wishlist"
|
||||||
return render_template("wishlist_add.html", user=session.get('user', {}), errormsg=errormsg)
|
return render_template("wishlist_add.html", user=session.get('user', {}), successmsg=None, errormsg=errormsg)
|
||||||
|
|
||||||
name = request.form['name'].strip().replace("\n", "")
|
name = request.form['name'].strip().replace("\n", "")
|
||||||
description = request.form['description'].strip().replace("\n", "")
|
description = request.form['description'].strip().replace("\n", "")
|
||||||
|
@ -153,11 +154,10 @@ def add_to_wishlist():
|
||||||
|
|
||||||
for check, errormsg in checks:
|
for check, errormsg in checks:
|
||||||
if not check:
|
if not check:
|
||||||
return render_template("wishlist_add.html", user=session.get('user', {}), errormsg=errormsg)
|
return render_template("wishlist_add.html", user=session.get('user', {}), successmsg=None, errormsg=errormsg)
|
||||||
|
|
||||||
slug = slugify(name)
|
slug = slugify(name)
|
||||||
|
github = Github(config["GITHUB_TOKEN"])
|
||||||
github = Github((config["GITHUB_LOGIN"], config["GITHUB_TOKEN"]))
|
|
||||||
author = InputGitAuthor(config["GITHUB_LOGIN"], config["GITHUB_EMAIL"])
|
author = InputGitAuthor(config["GITHUB_LOGIN"], config["GITHUB_EMAIL"])
|
||||||
repo = github.get_repo("Yunohost/apps")
|
repo = github.get_repo("Yunohost/apps")
|
||||||
current_wishlist_rawtoml = repo.get_contents("wishlist.toml", ref="app-store") # FIXME : ref=repo.default_branch)
|
current_wishlist_rawtoml = repo.get_contents("wishlist.toml", ref="app-store") # FIXME : ref=repo.default_branch)
|
||||||
|
@ -166,7 +166,7 @@ def add_to_wishlist():
|
||||||
new_wishlist = toml.loads(current_wishlist_rawtoml)
|
new_wishlist = toml.loads(current_wishlist_rawtoml)
|
||||||
|
|
||||||
if slug in new_wishlist:
|
if slug in new_wishlist:
|
||||||
return render_template("wishlist_add.html", user=session.get('user', {}), errormsg=f"An entry with the name {slug} already exists in the wishlist")
|
return render_template("wishlist_add.html", user=session.get('user', {}), successmsg=None, errormsg=f"An entry with the name {slug} already exists in the wishlist")
|
||||||
|
|
||||||
new_wishlist[slug] = {
|
new_wishlist[slug] = {
|
||||||
"name": name,
|
"name": name,
|
||||||
|
@ -182,15 +182,17 @@ def add_to_wishlist():
|
||||||
# Get the commit base for the new branch, and create it
|
# Get the commit base for the new branch, and create it
|
||||||
commit_sha = repo.get_branch("app-store").commit.sha # FIXME app-store -> repo.default_branch
|
commit_sha = repo.get_branch("app-store").commit.sha # FIXME app-store -> repo.default_branch
|
||||||
repo.create_git_ref(ref=f"refs/heads/{new_branch}", sha=commit_sha)
|
repo.create_git_ref(ref=f"refs/heads/{new_branch}", sha=commit_sha)
|
||||||
except:
|
except exception as e:
|
||||||
print("... Branch already exists, skipping")
|
print("... Failed to create branch ?")
|
||||||
return False
|
print(e)
|
||||||
|
errormsg = "Failed to create the pull request to add the app to the wishlist ... please report the issue to the yunohost team"
|
||||||
|
return render_template("wishlist_add.html", user=session.get('user', {}), successmsg=None, errormsg=errormsg)
|
||||||
|
|
||||||
message = f"Add {name} to wishlist"
|
message = f"Add {name} to wishlist"
|
||||||
repo.update_file(
|
repo.update_file(
|
||||||
"wishlist.toml",
|
"wishlist.toml",
|
||||||
message=message,
|
message=message,
|
||||||
content=new_wishlist,
|
content=new_wishlist_rawtoml,
|
||||||
sha=current_wishlist_sha,
|
sha=current_wishlist_sha,
|
||||||
branch=new_branch,
|
branch=new_branch,
|
||||||
author=author,
|
author=author,
|
||||||
|
@ -202,18 +204,22 @@ def add_to_wishlist():
|
||||||
body = f"""
|
body = f"""
|
||||||
### Add {name} to wishlist
|
### Add {name} to wishlist
|
||||||
|
|
||||||
|
Proposed by **{session['user']['username']}**
|
||||||
|
|
||||||
- [ ] Confirm app is self-hostable and generally makes sense to possibly integrate in YunoHost
|
- [ ] Confirm app is self-hostable and generally makes sense to possibly integrate in YunoHost
|
||||||
- [ ] Confirm app's license is opensource/free software (or not-totally-free, case by case TBD)
|
- [ ] Confirm app's license is opensource/free software (or not-totally-free, case by case TBD)
|
||||||
- [ ] Description describes concisely what the app is/does
|
- [ ] Description describes concisely what the app is/does
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Open the PR
|
# Open the PR
|
||||||
pr = self.repo.create_pull(
|
pr = repo.create_pull(
|
||||||
title=message, body=body, head=new_branch, base="app-store" # FIXME app-store -> repo.default_branch
|
title=message, body=body, head=new_branch, base="app-store" # FIXME app-store -> repo.default_branch
|
||||||
)
|
)
|
||||||
|
|
||||||
|
successmsg = f"Your proposed app has succesfully been submitted. It must now be validated by the YunoHost team. You can track progress here: https://github.com/YunoHost/apps/pull/{pr.number}"
|
||||||
|
return render_template("wishlist_add.html", user=session.get('user', {}), successmsg=successmsg)
|
||||||
else:
|
else:
|
||||||
return render_template("wishlist_add.html", user=session.get('user', {}), errormsg=None)
|
return render_template("wishlist_add.html", user=session.get('user', {}), successmsg=None, errormsg=None)
|
||||||
|
|
||||||
|
|
||||||
################################################
|
################################################
|
||||||
|
|
|
@ -9,6 +9,16 @@
|
||||||
|
|
||||||
<div class="overflow-x-auto max-w-md mx-auto pt-5">
|
<div class="overflow-x-auto max-w-md mx-auto pt-5">
|
||||||
|
|
||||||
|
{% if successmsg %}
|
||||||
|
<div role="alert" class="rounded-md border-s-4 border-green-500 bg-green-50 p-4 my-5">
|
||||||
|
<p class="mt-2 text-sm text-green-700 font-bold">
|
||||||
|
<i class="fa fa-thumbs-up fa-fw" aria-hidden="true"></i>
|
||||||
|
{{ successmsg }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
|
||||||
{% if not user %}
|
{% if not user %}
|
||||||
<div role="alert" class="rounded-md border-s-4 border-orange-500 bg-orange-50 p-4 mb-5">
|
<div role="alert" class="rounded-md border-s-4 border-orange-500 bg-orange-50 p-4 mb-5">
|
||||||
<p class="mt-2 text-sm text-orange-700 font-bold">
|
<p class="mt-2 text-sm text-orange-700 font-bold">
|
||||||
|
@ -63,6 +73,7 @@
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue