Skip to content

Commit

Permalink
fix: prevent adding sibling to top level hardware item (#986)
Browse files Browse the repository at this point in the history
* ci: add workflow for PR assign

* ci: add step to upload wheel to release

* ci: add step to build pdf documentation

* fix: prevent adding sibling to top-level item or sibling to part

* refactor: change error dialog message hyperlink to RAMSTK issue page

* 'Refactored by Sourcery' (#987)

Co-authored-by: Sourcery AI <>

* style: fix formatting warnings

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
  • Loading branch information
weibullguy and sourcery-ai[bot] authored Feb 20, 2022
1 parent fce6cae commit 8e0b66f
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 83 deletions.
45 changes: 22 additions & 23 deletions .github/workflows/do_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
# - Get release version from VERSION.
# - IF 'Release' label:
# - Cut release.
# - IF release is cut:
# - Build artifacts.
# - Upload to Test PyPi if build succeeds.
# - Test install from Test PyPi.
# - Upload to PyPi if test install succeeds.
# - Add wheel to GitHub release.
# - Build pdf documentation.
# - Add pdf documentation to GitHub release.
# - Job 2 (needs job 1):
# - Build artifacts.
# - Upload to Test PyPi.
# - Test install from Test PyPi.
# - Upload to PyPi.
# - Add wheel to GitHub release.
# - Build pdf documentation.
# - Add pdf documentation to GitHub release.
# - Job 3 (needs job 1):
# - Close old milestone.
# - Create new minor version milestone.
# - Create new major version milestone.
Expand Down Expand Up @@ -43,11 +43,13 @@ jobs:
- name: Get release version
id: relversion
if: contains(steps.prlabels.outputs.labels, ' Release ')
run: echo "::set-output name=rel_version::$(echo $(cat VERSION))"
run: |
echo "::set-output name=rel_version::$(echo $(cat VERSION))"
echo echo "cut_release=1" >> $GITHUB_ENV
- name: Cut release
- name: Cut the release
id: cutrelease
if: contains(steps.prlabels.outputs.labels, ' Release ')
if: ${{ env.cut_release == 1 }}
uses: release-drafter/release-drafter@master
with:
name: "v${{ steps.relversion.outputs.rel_version }}"
Expand All @@ -63,20 +65,11 @@ jobs:
echo ${{ steps.cutrelease.outputs.id }}
echo ${{ steps.cutrelease.outputs.name }}
echo ${{ steps.cutrelease.outputs.tag_name }}
echo ${{ steps.cutrelease.outputs.body }}
echo ${{ steps.cutrelease.outputs.html_url }}
echo ${{ steps.cutrelease.outputs.upload_url }}
build-deploy:
name: Build and Deploy RAMSTK
needs: cut-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Build release
if: startsWith(steps.cutrelease.outputs.tag_name, 'v')
id: build
run: |
pip install -U pip poetry twine
Expand Down Expand Up @@ -106,6 +99,13 @@ jobs:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}

- name: Upload wheel to Release
id: upload-wheel
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ steps.cutrelease.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./dist/*.whl

create_new_milestone:
name: Create New Milestone
needs: cut-release
Expand All @@ -117,8 +117,7 @@ jobs:

- name: Get new version
id: newversion
run: |
echo "::set-output name=version::$(echo $(cat VERSION))"
run: echo "::set-output name=version::$(echo $(cat VERSION))"

- name: Get next semantic version
id: nextversion
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/on-issue-assign.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# This workflow runs when an issue is assigned.
#
# - Job 1:
# - Checks for dobranch label
# - IF dobranch label exists:
# - Creates a new branch in the repository using the rules in
# issue-branch.yml
# - Job 2:
# - Removes status: backlog label and adds status: inprogress label to
# issue.
name: Issue Assigned Workflow
on:
issues:
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/on-pr-assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This workflow runs when a pull request is assigned.
#
# - Job 1:
# - Adds status: inprogress label to PR
name: Pull Request Assign Workflow

on:
pull_request:
types:
- assigned

jobs:
label_pr_in_progress:
runs-on: ubuntu-latest
steps:
- name: Add in progress label
uses: andymckay/labeler@master
with:
add-labels: "status: inprogress"
19 changes: 13 additions & 6 deletions .github/workflows/on-pr-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Execute Sphinx
uses: ammaraskar/sphinx-action@master
with:
docs-folder: "docs/"
- name: Build html documentation
run: |
cd docs
make html
cd ..
- name: Build pdf documentation
run: |
cd docs
make latexpdf LATEXMKOPTS="-silent -f"
cd ..
- name: Import GPG key
id: import_gpg
Expand All @@ -69,7 +76,7 @@ jobs:
git_user_signingkey: true
git_commit_gpgsign: true

- name: Commit RAMSTK Documentation Changes
- name: Commit RAMSTK documentation changes
run: |
git clone https://github.com/ReliaQualAssociates/ramstk.git --branch gh-pages --single-branch gh-pages
cp -fvr docs/_build/html/* gh-pages/
Expand All @@ -79,7 +86,7 @@ jobs:
git add .
git commit -a -m "Update documentation" && echo "do_push=1" >> $GITHUB_ENV || echo "Nothing to commit, working tree clean."
- name: Push RAMSTK Documentation Changes
- name: Push RAMSTK documentation changes
if: env.do_push == 1
uses: ad-m/github-push-action@master
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/on-push-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ on:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
create-release:
name: Create Release
request-release:
name: Request Release PR
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
./pyproject.toml
./docs/conf.py
- name: Cut release pull request
- name: Request release pull request
uses: peter-evans/create-pull-request@v3
with:
commit-message: "release: ${{ steps.newversion.outputs.new_version }}"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ help:
@echo " install install RAMSTK and all data files in the current (virtualenv) environment."
@echo " install.dev install only the RAMSTK code in the current (virtualenv) environment."
@echo " uninstall remove RAMSTK from the current (virtualenv) environment."
@echo " dist build source and wheel packages."
@echo " build build source and wheel packages."
@echo " release package and upload a release to PyPi."
@echo ""
@echo "The following variables are recognized by this Makefile. They can be changed in this file or passed on the command line."
Expand Down
2 changes: 2 additions & 0 deletions src/ramstk/views/gtk3/hardware/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ def __init__(self) -> None:
self.lst_manufacturers: List[str] = [""]

# Initialize public scalar class attributes.
self.part: int = 0

super().do_set_properties()
super().do_make_panel()
Expand Down Expand Up @@ -710,6 +711,7 @@ def _on_row_change(self, selection: Gtk.TreeSelection) -> None:
if _attributes:
self._record_id = _attributes["hardware_id"]
self._parent_id = _attributes["parent_id"]
self.part = _attributes["part"]

_attributes["category_id"] = self.lst_categories.index(
_attributes["category_id"]
Expand Down
104 changes: 80 additions & 24 deletions src/ramstk/views/gtk3/hardware/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,39 @@ def _do_request_insert_child(self, __button: Gtk.ToolButton) -> Any:
"record_id": self.dic_pkeys["record_id"],
}

if self._pnlPanel.part == 1:
_message = _(
"You cannot add a sibling item to a part. First set the "
"component category to nothing to convert this part to an "
"assembly and then try again."
)
_parent = (
self.get_parent().get_parent().get_parent().get_parent().get_parent()
)
_dialog = super().do_raise_dialog(parent=_parent)
_dialog.do_set_message(message=_message)
_dialog.do_set_message_type(message_type="information")
_dialog.do_run()
_dialog.do_destroy()
return

super().do_set_cursor_busy()
pub.sendMessage(
"request_insert_hardware",
attributes=copy(_attributes),
)

# See Issue #985.
_attributes.pop("part")
for _message in [
"request_insert_design_electric",
"request_insert_design_mechanic",
"request_insert_milhdbk217f",
"request_insert_nswc",
"request_insert_reliability",
for _table in [
"design_electric",
"design_mechanic",
"milhdbk217f",
"nswc",
"reliability",
]:
pub.sendMessage(
_message,
f"request_insert_{_table}",
attributes=copy(_attributes),
)

Expand All @@ -244,21 +262,39 @@ def _do_request_insert_part(self, __button: Gtk.ToolButton) -> None:
"record_id": self.dic_pkeys["record_id"],
}

if self._pnlPanel.part == 1:
_message = _(
"You cannot add a part to another part. First set the "
"component category to nothing to convert this part to an "
"assembly and then try again."
)
_parent = (
self.get_parent().get_parent().get_parent().get_parent().get_parent()
)
_dialog = super().do_raise_dialog(parent=_parent)
_dialog.do_set_message(message=_message)
_dialog.do_set_message_type(message_type="information")
_dialog.do_run()
_dialog.do_destroy()
return

super().do_set_cursor_busy()
pub.sendMessage(
"request_insert_hardware",
attributes=copy(_attributes),
)

# See Issue #985.
_attributes.pop("part")
for _message in [
"request_insert_design_electric",
"request_insert_design_mechanic",
"request_insert_milhdbk217f",
"request_insert_nswc",
"request_insert_reliability",
for _table in [
"design_electric",
"design_mechanic",
"milhdbk217f",
"nswc",
"reliability",
]:
pub.sendMessage(
_message,
f"request_insert_{_table}",
attributes=copy(_attributes),
)

Expand All @@ -276,21 +312,41 @@ def _do_request_insert_sibling(self, __button: Gtk.ToolButton) -> Any:
"record_id": self.dic_pkeys["record_id"],
}

if self.dic_pkeys["parent_id"] == 0:
_message = _(
"You cannot have two top-level items for a single revision. "
"If you want to add a new system, you need create a new RAMSTK "
"Program database. If you want to add a new configuration, "
"variant, etc. of the system in this Program database, "
"add a new Revision."
)
_parent = (
self.get_parent().get_parent().get_parent().get_parent().get_parent()
)
_dialog = super().do_raise_dialog(parent=_parent)
_dialog.do_set_message(message=_message)
_dialog.do_set_message_type(message_type="information")
_dialog.do_run()
_dialog.do_destroy()
return

super().do_set_cursor_busy()
pub.sendMessage(
"request_insert_hardware",
attributes=copy(_attributes),
)

# See Issue #985.
_attributes.pop("part")
for _message in [
"request_insert_design_electric",
"request_insert_design_mechanic",
"request_insert_milhdbk217f",
"request_insert_nswc",
"request_insert_reliability",
for _table in [
"design_electric",
"design_mechanic",
"milhdbk217f",
"nswc",
"reliability",
]:
pub.sendMessage(
_message,
f"request_insert_{_table}",
attributes=copy(_attributes),
)

Expand Down Expand Up @@ -424,9 +480,9 @@ def __init__(
super().__init__(configuration, logger)

# Initialize private dictionary attributes.
self._dic_icons["comp_ref_des"] = (
self.RAMSTK_USER_CONFIGURATION.RAMSTK_ICON_DIR + "/32x32/rollup.png"
)
self._dic_icons[
"comp_ref_des"
] = f"{self.RAMSTK_USER_CONFIGURATION.RAMSTK_ICON_DIR}/32x32/rollup.png"

# Initialize private list attributes.

Expand Down
Loading

0 comments on commit 8e0b66f

Please sign in to comment.