Skip to content

Commit

Permalink
Merge pull request #77 from TogetherCrew/feature/commit-info
Browse files Browse the repository at this point in the history
feat: add more relationship between commit and user
  • Loading branch information
scientiststwin authored Mar 13, 2024
2 parents 9bcc3ca + 0b890fb commit 88fd59c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 16 additions & 1 deletion dags/github/neo4j_storage/commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def save_commit_to_neo4j(commit: dict, repository_id: str):
driver = neo4jConnection.connect_neo4j()

committer = commit.pop("committer", None)
author = commit.pop("author", None)
cleaned_commit = flat_map(commit)

if committer:
Expand All @@ -16,12 +17,24 @@ def save_commit_to_neo4j(commit: dict, repository_id: str):
MERGE (ghu:{Node.GitHubUser.value} {{id: $committer.id}})
SET ghu += $committer, ghu.latestSavedAt = datetime()
WITH c, ghu
MERGE (ghu)-[cc:{Relationship.COMMITTED.value}]->(c)
MERGE (ghu)-[cc:{Relationship.COMMITTED_BY.value}]->(c)
SET cc.latestSavedAt = datetime()
"""
else:
committer_query = ""

if author:
author_query = f"""
WITH c
MERGE (ghu:{Node.GitHubUser.value} {{id: $author.id}})
SET ghu += $author, ghu.latestSavedAt = datetime()
WITH c, ghu
MERGE (ghu)-[ca:{Relationship.AUTHORED_BY.value}]->(c)
SET ca.latestSavedAt = datetime()
"""
else:
author_query = ""

with driver.session() as session:
session.execute_write(
lambda tx: tx.run(
Expand All @@ -30,10 +43,12 @@ def save_commit_to_neo4j(commit: dict, repository_id: str):
SET c += $commit, c.repository_id = $repository_id, c.latestSavedAt = datetime()
{ committer_query }
{ author_query }
""",
commit=cleaned_commit,
repository_id=repository_id,
committer=committer,
author=author,
)
)

Expand Down
3 changes: 2 additions & 1 deletion dags/github/neo4j_storage/neo4j_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Relationship(Enum):
IS_REVIEWER = "IS_REVIEWER"
REVIEWED = "REVIEWED"
HAS_LABEL = "HAS_LABEL"
COMMITTED = "COMMITTED"
COMMITTED_BY = "COMMITTED_BY"
AUTHORED_BY = "AUTHORED_BY"
IS_ON = "IS_ON"
CHANGED = "CHANGED"

0 comments on commit 88fd59c

Please sign in to comment.