Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve synced issue description and add NLnet page #145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions admin/scripts/sync_issues.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/bin/python

import argparse
import json
import logging
import sys
import textwrap
from dataclasses import dataclass, field
from time import sleep
from typing import List

import ijson
import pandas as pd
from common.ghkit import GitClient
from common.models.notion import Project, Subgrant
from common.models.notion import Subgrant
from common.utils import (
cleanup_empty,
cleanup_urls,
Expand Down Expand Up @@ -85,9 +86,29 @@ def __init__(self) -> None:

@dataclass
class GitProject:
@dataclass
class Description(str):
websites: str = ""
nlnet_pages: str = ""
source_code: str = ""

def __str__(self):
return textwrap.dedent(f"""
### NLnet Projects
{self.nlnet_pages}

### Websites
{self.websites}
""")

def __repr__(self):
return self.__str__()

name: str
subgrants: list[str] = field(default_factory=list)

branch_name: str = field(init=False)
description: str = "\n### Websites" # TODO: turn into a class
description: Description = field(default_factory=Description)
websites: Series = field(default_factory=Series)

def __post_init__(self):
Expand All @@ -98,9 +119,15 @@ def append_websites(self, websites: List[str]):
[self.websites, pd.Series(websites)], ignore_index=True
)

def update_nlnet_links(self, subgrants: list[str]):
self.description.nlnet_pages = "\n".join(
f"- https://nlnet.nl/project/{s}" for s in subgrants
)

def update_description(self):
self.clean_websites()
for site in self.websites:
self.description += f"\n- {site}"
self.description.websites += f"\n- {site}"

def clean_websites(self):
"""Remove empty values, clean up URLs and remove duplicates"""
Expand All @@ -110,12 +137,11 @@ def clean_websites(self):


class Subgrants(BaseModel):
subgrants: List[Subgrant] = []
subgrants: dict[str, Subgrant]

def get_websites(self, name: str) -> List[str]:
for s in self.subgrants:
if name == s.name:
return s.websites
def get_websites(self, name: str) -> list[str]:
if name in self.subgrants:
return self.subgrants[name].websites
return []


Expand Down Expand Up @@ -146,13 +172,13 @@ def main():

projects_dict = projects.to_dict(orient="records")
projects = [
Project(name=item["Name"], subgrants=item["Subgrants"])
GitProject(name=item["Name"], subgrants=item["Subgrants"])
for item in projects_dict
]

try:
with args.dashboard_file as f:
funds = Subgrants(subgrants=ijson.items(f, "."))
with args.metadata_file as f:
funds = Subgrants(subgrants=json.load(f))
except ValidationError as e:
logger.error(f"Failed to parse {args.metadata_file}: {e}")
exit()
Expand All @@ -175,7 +201,7 @@ def main():
for subgrant in project.subgrants:
p.append_websites(funds.get_websites(subgrant))

p.clean_websites()
p.update_nlnet_links(project.subgrants)
p.update_description()

logger.debug(f"{p.branch_name}\n{p.description}\n")
Expand Down