Skip to content

Commit

Permalink
Added Latin e.g. to test (#181)
Browse files Browse the repository at this point in the history
* Added Latin e.g. to test

* Deleted paths as created from another gh-action

* Added requirements.txt as called in gh-action

* Added Turing way pull_files test

* Updated PR url from Turing Way to NHS-R

* Removed Latin
  • Loading branch information
Lextuga007 authored Dec 13, 2024
1 parent 5668de7 commit 7b64801
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/no-bad-latin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ on:
pull_request:
branches:
- main
paths:
- "_book/"

# Set up the Continuous Integration job
jobs:
Expand Down
78 changes: 78 additions & 0 deletions tests/pull_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""
Script to pull changed files in a Pull Request using a GET resquest to the
GitHub API. Copyright The Turing Way Community https://github.com/the-turing-way/the-turing-way
"""
import requests
import argparse


def parse_args():
"""Construct the command line interface for the script"""
DESCRIPTION = "Script to check for occurences of 'Lorem Ipsum' in Markdown files"
parser = argparse.ArgumentParser(description=DESCRIPTION)

parser.add_argument(
"--pull-request",
type=str,
default=None,
help="If the script is be run on files changed by a pull request, parse the PR number",
)

return parser.parse_args()


def get_files_from_pr(pr_num):
"""Return a list of changed files from a GitHub Pull Request
Arguments:
pr_num {str} -- Pull Request number to get modified files from
Returns:
{list} -- List of modified filenames
"""
files = []
pr_url = f"https://api.github.com/repos/nhs-r-community/NHSR-way/pulls/{pr_num}/files"
resp = requests.get(pr_url)

# Raising for status to avoid ending up with red-herring tracebacks later
resp.raise_for_status()

for item in resp.json():
files.append(item["filename"])

return files


def filter_files(pr_num, start_phrase="book/website", ignore_suffix=None):
"""Filter modified files from a Pull Request by a start phrase
Arguments:
pr_num {str} -- Number of the Pull Request to get modified files from
Keyword Arguments:
start_phrase {str} -- Start phrase to filter changed files by
(default: {"book/website"})
ignore_suffix {str} -- File suffix or tuple of suffixes to ignore.
Returns:
{list} -- List of filenames that begin with the desired start phrase
"""
files = get_files_from_pr(pr_num)
filtered_files = []

if ignore_suffix is None:
ignore_suffix = ()

for filename in files:
if filename.startswith(start_phrase) and not filename.endswith(ignore_suffix):
filtered_files.append(filename)

return filtered_files


if __name__ == "__main__":
args = parse_args()
changed_files = filter_files(args.pull_request)
print(changed_files)
3 changes: 3 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jsonschema
requests
ruamel.yaml

0 comments on commit 7b64801

Please sign in to comment.