Skip to content

Commit

Permalink
Compare refs both ways round, other small updates (#4)
Browse files Browse the repository at this point in the history
* add header print function

* update images

* pretty print

* check commits both ways round

* update readme

* bump version to v0.2.0
  • Loading branch information
addepar-tg committed Jun 18, 2024
1 parent f845662 commit 7b2e9ad
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 30 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div align="center">
<a href="https://github.com/Addepar/RedFlag">
<img src="docs/images/RedFlag-Logo.png" alt="RedFlag" height="100">
<img src="https://raw.githubusercontent.com/Addepar/RedFlag/main/docs/images/RedFlag-Logo.png" alt="RedFlag" height="100">
</a>


Expand Down Expand Up @@ -277,13 +277,13 @@ Say hi to Addepar Security Engineering at [[email protected]](mai
[issues-shield]: https://img.shields.io/github/issues/Addepar/RedFlag.svg?style=for-the-badge
[issues-url]: https://github.com/Addepar/RedFlag/issues
[license-shield]: https://img.shields.io/github/license/Addepar/RedFlag.svg?style=for-the-badge
[license-url]: https://github.com/Addepar/RedFlag/blob/main/LICENSE.txt
[license-url]: https://github.com/Addepar/RedFlag/blob/main/LICENSE.md
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
[linkedin-url]: https://www.linkedin.com/company/addepar
[animated-report]: docs/images/Report-Animated.gif
[animated-report]: https://raw.githubusercontent.com/Addepar/RedFlag/main/docs/images/Report-Animated.gif
[animated-report-url]: TBD
[batch-workflow]: docs/images/Batch-Workflow.png
[batch-workflow]: https://raw.githubusercontent.com/Addepar/RedFlag/main/docs/images/Batch-Workflow.png
[docs-ci-mode]: https://img.shields.io/badge/Read%20More-How%20To%20Use%20RedFlag%20In%20CI%20Mode-blue?style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAMKADAAQAAAABAAAAMAAAAADbN2wMAAABcUlEQVRoBe1ZQU7DMBBsOPMC3gISDwDxAr5BJe5I/Ki3gkS58ROO9MKFdJZmLyOysWIzUNiVVs527Rl7JrnUi8V/iL7vr5CPyC1SFQ9NtMVu71U7Zp7qAwDQlLd4R94gT6pBCwCM0KJgajwFGPbaWCzjmW27e8o2B3gbwD6Vx/Ozg3/DuHEZHNvraDyKmugdU/+D6pZle2xXAuPBvkJ+BvuIl8hf9xF30Ttgu4/6ot6m67qzMa6pb8DXneNhhXz1H4Tj6Wwuc8BiDGDfHe+PrSv9vQS/1IFSTvm8PIBcciJMB0gQeZkOyCUnwnSABJGX6YBcciJMB0gQeZkOyCUnwnSABJGX6YBcciJMB0gQeZkOyCUnwnSABJGX6YBcciJMB0gQefnnHdiapPibW3IzM8e+KQdeBtDrOeA/vgbKXw6XDF/ekZVcQNQcogQ/vCMzcoDcYbit2UjtWtyRTe4z5MAhLpBrpF9841EWT+HmDr25A8AdiN2uwvv8AAAAAElFTkSuQmCC
[docs-ci-mode-url]: https://github.com/Addepar/RedFlag/wiki/CI-Mode
[docs-eval-mode]: https://img.shields.io/badge/Read%20More-How%20To%20Use%20RedFlag%20In%20Evaluation%20Mode-blue?style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAMKADAAQAAAABAAAAMAAAAADbN2wMAAABcUlEQVRoBe1ZQU7DMBBsOPMC3gISDwDxAr5BJe5I/Ki3gkS58ROO9MKFdJZmLyOysWIzUNiVVs527Rl7JrnUi8V/iL7vr5CPyC1SFQ9NtMVu71U7Zp7qAwDQlLd4R94gT6pBCwCM0KJgajwFGPbaWCzjmW27e8o2B3gbwD6Vx/Ozg3/DuHEZHNvraDyKmugdU/+D6pZle2xXAuPBvkJ+BvuIl8hf9xF30Ttgu4/6ot6m67qzMa6pb8DXneNhhXz1H4Tj6Wwuc8BiDGDfHe+PrSv9vQS/1IFSTvm8PIBcciJMB0gQeZkOyCUnwnSABJGX6YBcciJMB0gQeZkOyCUnwnSABJGX6YBcciJMB0gQeZkOyCUnwnSABJGX6YBcciJMB0gQefnnHdiapPibW3IzM8e+KQdeBtDrOeA/vgbKXw6XDF/ekZVcQNQcogQ/vCMzcoDcYbit2UjtWtyRTe4z5MAhLpBrpF9841EWT+HmDr25A8AdiN2uwvv8AAAAAElFTkSuQmCC
Expand Down
28 changes: 16 additions & 12 deletions addepar_redflag/redflag.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,26 +216,29 @@ async def redflag(
'Retrieved PRs',
MessageType.SUCCESS
)

# Get all commits between from and to
else:
count = 0
try:
compare = repository.compare(to_commit, from_commit)
# Get all commits between from and to
compare = repository.compare(from_commit, to_commit)

# If there are no commits, try the other way around
if not compare.ahead_by:
compare = repository.compare(to_commit, from_commit)

# If we can't find anything, exit
if not compare.ahead_by:
pretty_print(
'No PRs to evaluate, exiting.',
MessageType.FATAL
)
exit(0)
except UnknownObjectException as e:
pretty_print(
f'Failed to find the to and from refs: {e}',
MessageType.FATAL
)
exit(1)

if not compare.ahead_by:
pretty_print(
'No PRs to evaluate, exiting.',
MessageType.FATAL
)
exit(0)

# Flag for truncating SHA hashes in link text
to_hash = match('^[a-f0-9]{40}$', to_commit)
from_hash = match('^[a-f0-9]{40}$', from_commit)
Expand Down Expand Up @@ -277,6 +280,7 @@ async def redflag(
)

# Iterate over commits and create PR objects
count = 0
with progress:
for commit in commits:
lines = commit \
Expand Down Expand Up @@ -444,7 +448,7 @@ async def redflag(
filename = f'{repository.full_name.replace("/", "_")}-{base_filename.replace("/", "-")}-{datetime.now().strftime("%Y-%m-%d-%H-%M-%S")}'

jinja = Environment(
loader=PackageLoader("redflag"),
loader=PackageLoader("addepar_redflag"),
autoescape=select_autoescape()
)

Expand Down
6 changes: 2 additions & 4 deletions addepar_redflag/util/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from .console import (
pretty_print,
pretty_print_header,
pretty_print_traceback,
MessageType
)
Expand All @@ -36,10 +37,7 @@ def common_arguments(parser, default_config):


def cli():
pretty_print(
'Starting RedFlag 🚩',
MessageType.INFO
)
pretty_print_header()

# Load env var file, if present
load_dotenv()
Expand Down
10 changes: 5 additions & 5 deletions addepar_redflag/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
from os import getenv
from pathlib import Path

from .llm import (
DEFAULT_ROLE,
DEFAULT_REVIEW_QUESTION,
DEFAULT_TEST_PLAN_QUESTION
)
from .console import (
pretty_print,
pretty_print_config_table,
MessageType
)
from .llm import (
DEFAULT_ROLE,
DEFAULT_REVIEW_QUESTION,
DEFAULT_TEST_PLAN_QUESTION
)

def _update_nested_dict(
base,
Expand Down
16 changes: 12 additions & 4 deletions addepar_redflag/util/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class MessageType(Enum):

# Define the styles with emojis
styles = {
MessageType.SUCCESS: Style(color="green", bold=True),
MessageType.WARN: Style(color="yellow", bold=True),
MessageType.FATAL: Style(color="red", bold=True, underline=True),
MessageType.INFO: Style(color="blue", bold=True)
MessageType.SUCCESS: Style(color="green", bold=False),
MessageType.WARN: Style(color="yellow", bold=False),
MessageType.FATAL: Style(color="red", bold=False, underline=True),
MessageType.INFO: Style(color="blue", bold=False)
}

# Define the emojis
Expand All @@ -42,6 +42,14 @@ def str2bool(string: str) -> bool:
return string.lower() in ('yes', 'true', 't', 'y', '1')


# Helper function for standard formatting
def pretty_print_header():
CONSOLE.print(
"Starting [bold]RedFlag 🚩[/bold]",
style=Style()
)


# Helper function for standard formatting
def pretty_print(
message: str,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "addepar-redflag"
version = "0.1.0"
version = "0.2.0"
description = "RedFlag uses AI to identify high-risk code changes. Run it in batch mode for release candidate testing or in CI pipelines to flag PRs and add reviewers. RedFlag's flexible configuration makes it valuable for any team."
authors = ["Addepar Security Engineering <[email protected]>"]
repository = "https://github.com/Addepar/RedFlag"
Expand Down

0 comments on commit 7b2e9ad

Please sign in to comment.