Parse project commit
This commit is contained in:
parent
278c46a106
commit
4a23fbfbcc
|
@ -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.
|
||||
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.)
|
||||
|
||||
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`
|
||||
(they come disabled by default). You are now ready to go.
|
||||
|
||||
|
|
35
ganarchy.py
35
ganarchy.py
|
@ -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
|
||||
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>
|
||||
<body>
|
||||
<ul>
|
||||
{% for url, msg, img in repos %}
|
||||
{% for url, msg, img in repos -%}
|
||||
<li><a href="{{ url|e }}">{{ url|e }}</a>: {{ msg|e }}</li>
|
||||
{% endfor %}
|
||||
{%- endfor %}
|
||||
</ul>
|
||||
Powered by <a href="https://ganarchy.autistic.space/">GAnarchy</a>. AGPLv3-licensed. <a href="https://cybre.tech/SoniEx2/ganarchy">Source Code</a>.
|
||||
</body>
|
||||
|
@ -88,8 +89,8 @@ def initdb():
|
|||
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 INDEX url_key ON repo_history (url)''')
|
||||
c.execute('''CREATE TABLE config (git_commit TEXT, project_title TEXT)''')
|
||||
c.execute('''INSERT INTO config VALUES ('', '')''')
|
||||
c.execute('''CREATE TABLE config (git_commit TEXT)''')
|
||||
c.execute('''INSERT INTO config VALUES ('')''')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
@ -106,17 +107,6 @@ def set_commit(commit):
|
|||
conn.commit()
|
||||
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()
|
||||
def repo():
|
||||
"""Modifies repos to track"""
|
||||
|
@ -194,8 +184,8 @@ def cron_target():
|
|||
subprocess.call(["git", "-C", cache_home, "init", "-q"])
|
||||
conn = sqlite3.connect(data_home + "/ganarchy.db")
|
||||
c = conn.cursor()
|
||||
c.execute('''SELECT git_commit, project_title FROM config''')
|
||||
(project_commit, project_title) = c.fetchone()
|
||||
c.execute('''SELECT git_commit FROM config''')
|
||||
(project_commit,) = c.fetchone()
|
||||
entries = []
|
||||
generate_html = []
|
||||
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
|
||||
html_entries.append((url, msg, ""))
|
||||
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__":
|
||||
ganarchy()
|
||||
|
|
Loading…
Reference in New Issue