Skip to content

Commit

Permalink
feat: add case converter for matching keyword (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
chyccs committed Feb 4, 2023
1 parent 4deb270 commit dc1e8b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ PyGithub = "==1.57"
setuptools = "*"
wheel = "*"
semgrep = "*"
inflection = "*"

[requires]
python_version = "3.9"
23 changes: 16 additions & 7 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Set,
)

from inflection import humanize

from services import fetch_pull_request

TAG = [
Expand Down Expand Up @@ -54,33 +56,32 @@ def __parse_title(title: str):
def __highlight(text: str, keywords: Set[str]):
highlighted = text
for k in keywords:
if len(k) < 2 or k.find(','):
try:
highlighted = highlighted.replace(k, f'`{k}`')
except ValueError:
continue
highlighted = highlighted.replace(k, f'`{k}`')
return highlighted


def main():
owner = env['owner']
repo = env['repository']
pull_request_num = int(env['pull_request_number'])
token = env['access_token']
src_path = env['src_path']
symbols = env["symbols"]
keywords = set(symbols.split('\n'))
symbol_list = [humanize(symbol).lower().strip()
for symbol in symbols.split('\n') if len(humanize(symbol).lower().strip()) > 3]
symbol_list.extend([symbol.replace(' ', '_') for symbol in symbol_list])
keywords = set(symbol_list)

pull_request = fetch_pull_request(
access_token=token,
owner=owner,
repository=repo,
number=pull_request_num,
access_token=env['access_token'],
owner=env['owner'],
repository=env['repository'],
number=int(env['pull_request_number']),
)

if not __can_process(pull_request.title):
return

files = []
for root, _, f_names in os.walk(src_path):
for root, _, f_names in os.walk(env['src_path']):
for f in f_names:
file_path = os.path.join(root, f)
if file_path.startswith('./.venv'):
Expand Down

0 comments on commit dc1e8b3

Please sign in to comment.