Skip to content

Commit

Permalink
Git status can be read directly
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed May 7, 2023
1 parent 8c27000 commit 467c72b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ogc/na/ingest_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def process(input_files: str | Path | Sequence[str | Path],
while remaining_fn:
fn = str(remaining_fn.popleft())

if not fn or not os.path.isfile():
if not fn or not os.path.isfile(fn):
continue

if re.match(r'.*\.ya?ml$', fn):
Expand Down Expand Up @@ -706,7 +706,7 @@ def _process_cmdln():

parser.add_argument(
"input",
nargs='+',
nargs='*',
help="Source file (instead of service)",
)

Expand Down Expand Up @@ -783,14 +783,25 @@ def _process_cmdln():
help='Regular expression for URL whitelisting'
)

parser.add_argument(
'--use-git-status',
action='store_true',
help='Use git status for obtaining batch filenames'
)

args = parser.parse_args()

if args.domain_config:
domain_cfg = DomainConfiguration(args.domain_config)
else:
domain_cfg = None

result = process(args.input,
input_files = args.input
if args.batch and args.use_git_status:
git_status = util.git_status()
input_files = git_status['added'] + git_status['modified'] + [r[1] for r in git_status['renamed']]

result = process(input_files,
context_fn=args.context,
domain_cfg=domain_cfg,
jsonld_fn=args.json_ld_file if args.json_ld else False,
Expand Down
22 changes: 22 additions & 0 deletions ogc/na/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import requests
import rfc3987
import git
from rdflib import Graph
from pyshacl import validate as shacl_validate
from urllib.parse import urlparse
Expand Down Expand Up @@ -239,3 +240,24 @@ def deep_update(orig_dict: dict, with_dict: dict, replace: bool = False) -> dict
else:
dest[k] = v
return dest


def git_status(repo_path: str | Path = '.'):
repo = git.Repo(repo_path)
added = repo.untracked_files
modified = []
deleted = []
renamed = []
for diff in repo.head.commit.diff(None):
if diff.change_type == 'D':
deleted.append(diff.a_path)
elif diff.change_type == 'M':
modified.append(diff.a_path)
elif diff.chhange_type == 'R':
renamed.append((diff.a_path, diff.b_path))
return {
'added': added,
'modified': modified,
'deleted': deleted,
'renamed': renamed,
}

0 comments on commit 467c72b

Please sign in to comment.