Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ android_analysis = [
"android_inspector==0.0.1"
]
mining = [
"minecode_pipelines==0.0.1b1"
"minecode_pipelines==0.0.1b8"
]

[project.urls]
Expand Down
35 changes: 21 additions & 14 deletions scanpipe/pipes/federatedcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import requests
import saneyaml
from git import GitCommandError
from git import Repo
from packageurl import PackageURL

Expand Down Expand Up @@ -195,9 +196,20 @@ def commit_and_push_changes(
remote_name="origin",
logger=None,
):
"""Commit and push changes to remote repository."""
commit_changes(repo, files_to_commit, commit_message, purls)
push_changes(repo, remote_name)
"""
Commit and push changes to remote repository.
Returns True if changes are successfully pushed, False otherwise.
"""
try:
commit_changes(repo, files_to_commit, commit_message, purls, logger)
push_changes(repo, remote_name)
except GitCommandError as e:
if "nothing to commit" in e.stdout.lower():
logger("Nothing to commit, working tree clean.")
else:
logger(f"Error while committing change: {e}")
return False
return True


def commit_changes(
Expand All @@ -218,18 +230,9 @@ def commit_changes(
author_name = settings.FEDERATEDCODE_GIT_SERVICE_NAME
author_email = settings.FEDERATEDCODE_GIT_SERVICE_EMAIL

files_added = all(
[
True
for changed_file in files_to_commit
if changed_file in repo.untracked_files
]
)
change_type = "Add" if files_added else "Update"

purls = "\n".join(purls)
commit_message = f"""\
{change_type} {mine_type} results for:
Add {mine_type} results for:
{purls}

Tool: {tool_name}@v{tool_version}
Expand All @@ -239,7 +242,11 @@ def commit_changes(
"""

repo.index.add(files_to_commit)
repo.index.commit(textwrap.dedent(commit_message))
repo.git.commit(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keshav-space just wondering what the difference between repo.index.commit and repo.git.commit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonoYang repo.index is python abstraction of git while repo.git runs the native command line git. We switched from repo.index to repo.git for committing our changes because repo.index by default allows empty commits and there is no way to change this behavior. So we ended up using the native repo.git to disallow empty commits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that git is now a system requirement that needs to be installed too. Please double check the docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pombredanne we already have git as system requirement

git \

m=textwrap.dedent(commit_message),
allow_empty=False,
no_verify=True,
)


def delete_local_clone(repo):
Expand Down