Skip to content

Commit

Permalink
Merge pull request #50 from sebhmg/GEOPY-1342
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhmg authored Feb 8, 2024
2 parents d71a429 + 02fb1cf commit 9758736
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/pr_add_jira_summary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ jobs:
PR_TITLE: ${{ github.event.pull_request.title }}
run: >
echo $HEAD_REF $PR_TITLE
| echo "issue_key=$(grep -os "\b\(GA\|GEOPY\)-[0-9]\+" | head -n1)" >> $GITHUB_OUTPUT
| echo "issue_key=$(
grep -osi "\b\(GA\|GEOPY\)[ #-]*[0-9]\+"
| head -n1
| sed -E "s/([A-Z]+)[-# ]*([0-9]+)/\1-\2/i"
| tr [:lower:] [:upper:]
)"
>> $GITHUB_OUTPUT
- name: Get JIRA summary
id: get_jira_summary
if: ${{ steps.find_jira_key.outputs.issue_key }}
Expand All @@ -31,18 +37,26 @@ jobs:
-H "Authorization: Basic $JIRA_BASIC_AUTH"
-H "Content-Type: application/json"
"$JIRA_BASE_URL/rest/api/2/issue/${{ steps.find_jira_key.outputs.issue_key }}"
| echo "summary=$(jq -r '.fields.summary')" >> $GITHUB_OUTPUT
| echo "summary=$(jq -r '.fields.summary // empty')" >> $GITHUB_OUTPUT
- name: Extract PR title
id: get_pr_title
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
echo "text=$(echo $PR_TITLE | sed -E "s/^\s*[?[A-Z]+[-# ]*[0-9]+]?[-: ]*(.*)/\1/i")" >> $GITHUB_OUTPUT
- name: Add comment
if: ${{ steps.find_jira_key.outputs.issue_key }}
env:
ISSUE_SUMMARY: ${{ steps.get_jira_summary.outputs.summary }}
TITLE_TEXT: ${{ steps.get_pr_title.outputs.text }}
PR_BODY: ${{ github.event.pull_request.body }}
run: >
jq
--arg ISSUE_ID "${{ steps.find_jira_key.outputs.issue_key }}"
--arg ISSUE_SUMMARY "$(cat <<< $ISSUE_SUMMARY)"
--arg TITLE_TEXT "$(cat <<< ${TITLE_TEXT:-$ISSUE_SUMMARY})"
--arg PR_BODY "$(cat <<< $PR_BODY)"
-c '."body"="**" + $ISSUE_ID + " - " + $ISSUE_SUMMARY + "**\n" + $PR_BODY' <<< {}
-c '{"title": ($ISSUE_ID + ": " + $TITLE_TEXT), "body": ("**" + $ISSUE_ID + " - " + $ISSUE_SUMMARY + "**\n" + $PR_BODY)}' <<< {}
| curl -sS -X POST -d @-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}"
-H "Content-Type: application/json"
Expand Down
6 changes: 3 additions & 3 deletions omf/scripts/geoh5_to_omf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from omf.fileio import OMFWriter
from omf.fileio.geoh5 import GeoH5Reader

_logger = logging.getLogger(__package__)
_logger = logging.getLogger(__package__ + "." + Path(__file__).stem)


def run():
def main():
parser = argparse.ArgumentParser(
prog="geoh5_to_omf",
description="Converts a geoh5 file to a new OMF file.",
Expand Down Expand Up @@ -37,4 +37,4 @@ def run():


if __name__ == "__main__":
run()
main() # pragma: no cover
6 changes: 3 additions & 3 deletions omf/scripts/omf_to_geoh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from omf.fileio import OMFReader
from omf.fileio.geoh5 import GeoH5Writer

_logger = logging.getLogger(__package__)
_logger = logging.getLogger(__package__ + "." + Path(__file__).stem)


def run():
def main():
parser = argparse.ArgumentParser(
prog="omf_to_geoh5",
description="Converts an OMF file to a new geoh5 file.",
Expand Down Expand Up @@ -54,4 +54,4 @@ def run():


if __name__ == "__main__":
run()
main() # pragma: no cover
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ packages = [
]

[tool.poetry.scripts]
geoh5_to_omf = 'omf.scripts.geoh5_to_omf:run'
omf_to_geoh5 = 'omf.scripts.omf_to_geoh5:run'
geoh5_to_omf = 'omf.scripts.geoh5_to_omf:main'
omf_to_geoh5 = 'omf.scripts.omf_to_geoh5:main'

[tool.poetry.dependencies]
python = "^3.8,<3.11"
Expand Down
6 changes: 3 additions & 3 deletions tests/script_geoh5_to_omf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_geoh5_to_omf_without_output_name(geoh5_input_path: Path):
"""Test the geoh5_to_omf script."""

with patch("sys.argv", ["geoh5_to_omf", str(geoh5_input_path)]):
geoh5_to_omf.run()
geoh5_to_omf.main()

assert (geoh5_input_path.with_suffix(".omf")).exists()

Expand All @@ -55,7 +55,7 @@ def test_geoh5_to_omf_with_output_name(
with patch(
"sys.argv", ["geoh5_to_omf", str(geoh5_input_path), "-o", f"{output_name}"]
):
geoh5_to_omf.run()
geoh5_to_omf.main()

expected_output = working_dir / output_name
if not expected_output.suffix:
Expand All @@ -82,7 +82,7 @@ def test_geoh5_to_omf_with_absolute_output_path(
f"{(output_dir / output_name).absolute()}",
],
):
geoh5_to_omf.run()
geoh5_to_omf.main()

expected_output = output_dir / output_name
if not expected_output.suffix:
Expand Down
10 changes: 5 additions & 5 deletions tests/script_omf_to_geoh5_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_omf_to_geoh5_without_output_name(omf_input_path: Path):
"""Test the omf_to_geoh5 script."""

with patch("sys.argv", ["omf_to_geoh5", str(omf_input_path)]):
omf_to_geoh5.run()
omf_to_geoh5.main()

assert (omf_input_path.with_suffix(".geoh5")).exists()

Expand All @@ -57,7 +57,7 @@ def test_omf_to_geoh5_with_output_name(
with patch(
"sys.argv", ["omf_to_geoh5", str(omf_input_path), "-o", f"{output_name}"]
):
omf_to_geoh5.run()
omf_to_geoh5.main()

expected_output = working_dir / output_name
if not expected_output.suffix:
Expand All @@ -84,7 +84,7 @@ def test_omf_to_geoh5_with_absolute_output_path(
f"{(output_dir / output_name).absolute()}",
],
):
omf_to_geoh5.run()
omf_to_geoh5.main()

expected_output = output_dir / output_name
if not expected_output.suffix:
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_omf_to_geoh5_with_gzip_level(tmp_path: Path, gzip_level: int):
f"{output_path.absolute()}",
],
):
omf_to_geoh5.run()
omf_to_geoh5.main()

assert output_path.exists()

Expand All @@ -139,7 +139,7 @@ def test_omf_to_geoh5_with_gzip_level_too_high(capsys, tmp_path: Path):
f"{output_path.absolute()}",
],
):
omf_to_geoh5.run()
omf_to_geoh5.main()

assert not output_path.exists()
assert captured_exception.value.code == 2
Expand Down

0 comments on commit 9758736

Please sign in to comment.