Parse project commit

This commit is contained in:
SoniEx2 2019-04-20 17:12:39 -03:00
parent 278c46a106
commit 4a23fbfbcc
2 changed files with 40 additions and 46 deletions

View File

@ -11,12 +11,9 @@ First, initialize the database with `ganarchy.py initdb`. The database is stored
Then, set the project commit with `ganarchy.py set-commit COMMIT`, where `COMMIT` is the full commit hash. Then, set the project commit with `ganarchy.py set-commit COMMIT`, where `COMMIT` is the full commit hash.
The commit *must* start with `[Project]` followed by the project name, and may have an optional description. The commit *must* start with `[Project]` followed by the project name, and may have an optional description.
(Note: This requirement isn't currently checked, but will be in the future. This is important for a future federation (Note: This requirement isn't properly checked, but will be in the future. This is important for a future federation
protocol that allows for automatically discovering forks based on the project commit.) protocol that allows for automatically discovering forks based on the project commit.)
Currently, you also need to set the project title manually using `ganarchy.py set-project-title PROJECT-TITLE`. This will
be replaced with the above mechanism in the future.
Once everything is initialized, add some repos with `ganarchy.py repo add URL`, and enable them with `ganarchy.py repo enable URL` Once everything is initialized, add some repos with `ganarchy.py repo add URL`, and enable them with `ganarchy.py repo enable URL`
(they come disabled by default). You are now ready to go. (they come disabled by default). You are now ready to go.

View File

@ -45,13 +45,14 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<title>{{ project_title }}</title> <title>{{ project_title|e }}</title>
{% if project_desc %}<meta name="description" content="{{ project_desc|e }}" />{% endif %}
</head> </head>
<body> <body>
<ul> <ul>
{% for url, msg, img in repos %} {% for url, msg, img in repos -%}
<li><a href="{{ url|e }}">{{ url|e }}</a>: {{ msg|e }}</li> <li><a href="{{ url|e }}">{{ url|e }}</a>: {{ msg|e }}</li>
{% endfor %} {%- endfor %}
</ul> </ul>
Powered by <a href="https://ganarchy.autistic.space/">GAnarchy</a>. AGPLv3-licensed. <a href="https://cybre.tech/SoniEx2/ganarchy">Source Code</a>. Powered by <a href="https://ganarchy.autistic.space/">GAnarchy</a>. AGPLv3-licensed. <a href="https://cybre.tech/SoniEx2/ganarchy">Source Code</a>.
</body> </body>
@ -88,8 +89,8 @@ def initdb():
c.execute('''CREATE INDEX active_key ON repos (active)''') c.execute('''CREATE INDEX active_key ON repos (active)''')
c.execute('''CREATE TABLE repo_history (entry INTEGER PRIMARY KEY ASC AUTOINCREMENT, url TEXT, count INTEGER, head_commit TEXT)''') c.execute('''CREATE TABLE repo_history (entry INTEGER PRIMARY KEY ASC AUTOINCREMENT, url TEXT, count INTEGER, head_commit TEXT)''')
c.execute('''CREATE INDEX url_key ON repo_history (url)''') c.execute('''CREATE INDEX url_key ON repo_history (url)''')
c.execute('''CREATE TABLE config (git_commit TEXT, project_title TEXT)''') c.execute('''CREATE TABLE config (git_commit TEXT)''')
c.execute('''INSERT INTO config VALUES ('', '')''') c.execute('''INSERT INTO config VALUES ('')''')
conn.commit() conn.commit()
conn.close() conn.close()
@ -106,17 +107,6 @@ def set_commit(commit):
conn.commit() conn.commit()
conn.close() conn.close()
@ganarchy.command()
@click.argument('project-title')
def set_project_title(project_title):
"""Sets the project title"""
import re
conn = sqlite3.connect(data_home + "/ganarchy.db")
c = conn.cursor()
c.execute('''UPDATE config SET project_title=?''', (project_title,))
conn.commit()
conn.close()
@ganarchy.group() @ganarchy.group()
def repo(): def repo():
"""Modifies repos to track""" """Modifies repos to track"""
@ -194,8 +184,8 @@ def cron_target():
subprocess.call(["git", "-C", cache_home, "init", "-q"]) subprocess.call(["git", "-C", cache_home, "init", "-q"])
conn = sqlite3.connect(data_home + "/ganarchy.db") conn = sqlite3.connect(data_home + "/ganarchy.db")
c = conn.cursor() c = conn.cursor()
c.execute('''SELECT git_commit, project_title FROM config''') c.execute('''SELECT git_commit FROM config''')
(project_commit, project_title) = c.fetchone() (project_commit,) = c.fetchone()
entries = [] entries = []
generate_html = [] generate_html = []
for (e, url,) in c.execute("""SELECT max(e), url FROM (SELECT max(T1.entry) e, T1.url FROM repo_history T1 for (e, url,) in c.execute("""SELECT max(e), url FROM (SELECT max(T1.entry) e, T1.url FROM repo_history T1
@ -220,7 +210,14 @@ def cron_target():
# TODO process history into SVG # TODO process history into SVG
html_entries.append((url, msg, "")) html_entries.append((url, msg, ""))
template = jinja2.Template(TEMPLATE) template = jinja2.Template(TEMPLATE)
click.echo(template.render(project_title = project_title, repos = html_entries)) import re
project = subprocess.check_output(["git", "-C", cache_home, "show", project_commit, "-s", "--format=%B", "--"], stderr=subprocess.DEVNULL).decode("utf-8", "replace")
project_title, project_desc = (lambda x: x.groups() if x is not None else ('', None))(re.fullmatch('^\\[Project\\]\s+(.+?)(?:\n\n(.+))?$', project, flags=re.ASCII|re.DOTALL|re.IGNORECASE))
if not project_title.strip():
project_title, project_desc = ("Error parsing project commit",)*2
if project_desc:
project_desc = project_desc.strip()
click.echo(template.render(project_title = project_title, project_desc = project_desc, repos = html_entries))
if __name__ == "__main__": if __name__ == "__main__":
ganarchy() ganarchy()