Skip to content

Commit

Permalink
Update all spelling errors identified and path issues (Thanks @vgrassia
Browse files Browse the repository at this point in the history
…!)
  • Loading branch information
joseph-flinn committed Feb 29, 2024
1 parent ed12be6 commit 1c0c8f3
Show file tree
Hide file tree
Showing 33 changed files with 78 additions and 107 deletions.
4 changes: 1 addition & 3 deletions lint-workflow-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pipenv shell

### Testing

All built-in `src/rules` should have 100% code coverage and we should shoot for an overall coverage of 80%+.
All built-in `src/bitwarden_workflow_linter/rules` should have 100% code coverage and we should shoot for an overall coverage of 80%+.
We are lax on the
[imperative shell](https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell)
(code interacting with other systems; ie. disk, network, etc), but we strive to maintain a high coverage over the
Expand Down Expand Up @@ -124,8 +124,6 @@ class RuleJobNameExists(Rule):
return False, self.message
```

[TODO: Is this enough documentation on how to use?]

By default, a new Rule needs five things:

- `self.message`: The message to return to the user on a lint failure
Expand Down
3 changes: 1 addition & 2 deletions lint-workflow-v2/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "hatchling.build"
[project]
name = "bitwarden_workflow_linter"
dynamic = ["version"]
authors = []
authors = ["Bitwarden Inc"]
description = "Custom GitHub Action Workflow Linter"
readme = "README.md"
requires-python = ">=3.11"
Expand Down Expand Up @@ -35,7 +35,6 @@ dependencies = [
Homepage = "https://github.com/bitwarden/gh-actions/tree/main/lint-workflow-v2"
Issues = "https://github.com/bitwarden/gh-actions/issues"


[project.scripts]
bwwl = "bitwarden_workflow_linter.cli:main"

Expand Down
3 changes: 1 addition & 2 deletions lint-workflow-v2/pyproject.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "hatchling.build"
[project]
name = "bitwarden_workflow_linter"
dynamic = ["version"]
authors = []
authors = ["Bitwarden Inc"]
description = "Custom GitHub Action Workflow Linter"
readme = "README.md"
requires-python = ">=3.11"
Expand All @@ -23,7 +23,6 @@ $DEPS
Homepage = "https://github.com/bitwarden/gh-actions/tree/main/lint-workflow-v2"
Issues = "https://github.com/bitwarden/gh-actions/issues"


[project.scripts]
bwwl = "bitwarden_workflow_linter.cli:main"

Expand Down
24 changes: 12 additions & 12 deletions lint-workflow-v2/src/bitwarden_workflow_linter/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class ActionsCmd:
"""

def __init__(self, settings: Optional[Settings] = None) -> None:
"""Initialize the the ActionsCmd class.
"""Initialize the ActionsCmd class.
Args:
settings:
A Settings object that contains any default, overriden, or custom settings
A Settings object that contains any default, overridden, or custom settings
required anywhere in the application.
"""
self.settings = settings
Expand All @@ -41,12 +41,12 @@ def extend_parser(
) -> argparse._SubParsersAction:
"""Extends the CLI subparser with the options for ActionCmd.
Add 'actions add' and 'actions update' to the CLI as sub-commands
Add 'actions add' and 'actions update' to the CLI as subcommands
along with the options and arguments for each.
Args:
subparsers:
The main argument parser to add sub commands and arguments to
The main argument parser to add subcommands and arguments to
"""
parser_actions = subparsers.add_parser(
"actions", help="!!BETA!!\nAdd or Update Actions in the pre-approved list."
Expand All @@ -61,7 +61,7 @@ def extend_parser(
parser_actions_add = subparsers_actions.add_parser(
"add", help="add action to approved list"
)
parser_actions_add.add_argument("name", help="action name [git owener/repo]")
parser_actions_add.add_argument("name", help="action name [git owner/repo]")

return subparsers

Expand Down Expand Up @@ -96,13 +96,13 @@ def get_github_api_response(
return response

def exists(self, action: Action) -> bool:
"""Takes and action id and checks if the action repo exists."""
"""Takes an action id and checks if the action repository exists."""

url = f"https://api.github.com/repos/{action.name}"
response = self.get_github_api_response(url, action.name)

if response is None:
# Handle github api limit exceed by returning that the action exists
# Handle exceeding GitHub API limit by returning that the action exists
# without actually checking to prevent false errors on linter output. Only
# show it as an linter error.
return True
Expand Down Expand Up @@ -159,7 +159,7 @@ def save_actions(self, updated_actions: dict[str, Action], filename: str) -> Non
)

def add(self, new_action_name: str, filename: str) -> int:
"""Sub-command to add a new Action to the list of approved Actions.
"""Subcommand to add a new Action to the list of approved Actions.
'actions add' will add an Action and all of its metadata and dump all
approved actions (including the new one) to either the default JSON file
Expand All @@ -178,11 +178,11 @@ def add(self, new_action_name: str, filename: str) -> int:
return 0

def update(self, filename: str) -> int:
"""Sub-command to update all of the versions of the approved actions.
"""Subcommand to update all of the versions of the approved actions.
'actions update' will update all of the approved to the newest version
and dump all of the new data to either the default JSON file or the
one provided by '--output'
'actions update' will update all of the approved actions to the newest
version and dump all of the new data to either the default JSON file or
the one provided by '--output'
"""
print("Actions: update")
updated_actions = {}
Expand Down
4 changes: 2 additions & 2 deletions lint-workflow-v2/src/bitwarden_workflow_linter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from typing import List, Optional

from .actions import ActionsCmd
from .utils import Settings
from .lint import LinterCmd
from .utils import Settings


local_settings = Settings.factory()
Expand All @@ -17,7 +17,7 @@ def main(input_args: Optional[List[str]] = None) -> int:
"""CLI utility to lint GitHub Action Workflows.
A CLI utility to enforce coding standards on GitHub Action workflows. The
utility also provides other sub-commands to assist with other workflow
utility also provides other subcommands to assist with other workflow
maintenance tasks; such as maintaining the list of approved GitHub Actions.
"""
linter_cmd = LinterCmd(settings=local_settings)
Expand Down
14 changes: 7 additions & 7 deletions lint-workflow-v2/src/bitwarden_workflow_linter/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class LinterCmd:
"""

def __init__(self, settings: Optional[Settings] = None) -> None:
"""Initailized the LinterCmd class.
"""Initailize the LinterCmd class.
Args:
settings:
A Settings object that contains any default, overriden, or custom settings
A Settings object that contains any default, overridden, or custom settings
required anywhere in the application.
"""
self.rules = Rules(settings=settings)
Expand All @@ -36,11 +36,11 @@ def extend_parser(
) -> argparse._SubParsersAction:
"""Extends the CLI subparser with the options for LintCmd.
Add 'lint' as a sub command along with its options and arguments
Add 'lint' as a subcommand along with its options and arguments
Args:
subparsers:
The main argument parser to add sub commands and arguments to
The main argument parser to add subcommands and arguments to
"""
parser_lint = subparsers.add_parser(
"lint",
Expand Down Expand Up @@ -69,7 +69,7 @@ def get_max_error_level(self, findings: list[LintFinding]) -> int:
Args:
findings:
All of the findings that the linter found while linting a workflows.
All of the findings that the linter found while linting a workflow.
Return:
The numeric value of the maximum lint finding
Expand Down Expand Up @@ -127,7 +127,7 @@ def generate_files(self, files: list[str]) -> list[str]:
Args:
files:
list of file names or director names.
list of file names or directory names.
Returns:
A sorted set of all workflow files in the path(s) specified.
Expand All @@ -150,7 +150,7 @@ def run(self, input_files: list[str], strict: bool = False) -> int:
Args:
input_files:
list of file names or director names.
list of file names or directory names.
strict:
fail on WARNING instead of succeed
Expand Down
25 changes: 3 additions & 22 deletions lint-workflow-v2/src/bitwarden_workflow_linter/load.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Module to load for Worflows and Rules."""
"""Module to load for Workflows and Rules."""

import importlib

Expand Down Expand Up @@ -36,7 +36,7 @@ def __load_workflow_from_file(cls, filename: str) -> CommentedMap:
Returns:
A CommentedMap that contains the dict() representation of the
yaml file. It includes the comments as a part of their respective
YAML file. It includes the comments as a part of their respective
objects (depending on their location in the file).
"""
with open(filename, encoding="utf8") as file:
Expand All @@ -55,25 +55,6 @@ def __build_workflow(cls, loaded_yaml: CommentedMap) -> Workflow:
"""
return Workflow.init("", loaded_yaml)

# return Workflow.from_dict(
# {
# **loaded_yaml,
# "jobs": {
# str(job_key): Job.init(
# job_key,
# {
# **job,
# "steps": [
# Step.init(idx, job_key, step_data)
# for idx, step_data in enumerate(job["steps"])
# ],
# },
# )
# for job_key, job in loaded_yaml["jobs"].items()
# },
# }
# )

@classmethod
def build(
cls,
Expand Down Expand Up @@ -128,7 +109,7 @@ def __init__(self, settings: Settings) -> None:
Args:
settings:
A Settings object that contains any default, overriden, or custom settings
A Settings object that contains any default, overridden, or custom settings
required anywhere in the application.
"""
for rule in settings.enabled_rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Job:
"""Represents a job in a GitHub Action workflow.
This object contains all of the data that is required to run the current linting
Rules against. If a new Rule requies a key that is missing, the attribute should
Rules against. If a new Rule requires a key that is missing, the attribute should
be added to this class to make it available for use in linting.
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Step:
"""Represents a step in a GitHub Action workflow job.
This object contains all of the data that is required to run the current linting
Rules against. If a new Rule requies a key that is missing, the attribute should
Rules against. If a new Rule requires a key that is missing, the attribute should
be added to this class to make it available for use in linting.
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Workflow:
"""Represents an entire workflow in a GitHub Action workflow.
This object contains all of the data that is required to run the current linting
Rules against. If a new Rule requies a key that is missing, the attribute should
Rules against. If a new Rule requires a key that is missing, the attribute should
be added to this class to make it available for use in linting.
See src/models/job.py for an example if the key in the workflow data does not map
Expand Down
6 changes: 3 additions & 3 deletions lint-workflow-v2/src/bitwarden_workflow_linter/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class RuleExecutionException(Exception):
"""Exeception for the Base Rule class."""
"""Exception for the Base Rule class."""

pass

Expand All @@ -22,7 +22,7 @@ class Rule:
settings: Optional[Settings] = None

def fn(self, obj: Union[Workflow, Job, Step]) -> Tuple[bool, str]:
"""Execute the Rule (this should be overriden in the extending class.
"""Execute the Rule (this should be overridden in the extending class.
Args:
obj:
Expand Down Expand Up @@ -58,7 +58,7 @@ def build_lint_message(self, message: str, obj: Union[Workflow, Job, Step]) -> s
return f"{obj_type.__name__} => {message}"

def execute(self, obj: Union[Workflow, Job, Step]) -> Union[LintFinding, None]:
"""Wrapper function to execute the overriden self.fn().
"""Wrapper function to execute the overridden self.fn().
Run the Rule against the object and return the results. The result
could be an Exception message where the Rule cannot be run against
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from typing import Union, Optional, Tuple, List

from ..models.job import Job
from ..models.workflow import Workflow
from ..models.step import Step
from ..models.workflow import Workflow
from ..rule import Rule
from ..utils import LintLevels, Settings


class RuleJobEnvironmentPrefix(Rule):
"""Rule to enforce specific prefixes for environemnt variables.
"""Rule to enforce specific prefixes for environment variables.
Automated testing is not easily written for GitHub Action Workflows. CI can also
get complicated really quickly and take up hundreds of lines. All of this can
Expand All @@ -29,10 +29,10 @@ def __init__(self, settings: Optional[Settings] = None) -> None:
Args:
settings:
A Settings object that contains any default, overriden, or custom settings
A Settings object that contains any default, overridden, or custom settings
required anywhere in the application.
"""
self.message = "Job environment vars should start with and underscore:"
self.message = "Job environment vars should start with an underscore:"
self.on_fail = LintLevels.ERROR
self.compatibility = [Job]
self.settings = settings
Expand All @@ -57,7 +57,7 @@ def fn(self, obj: Job) -> Tuple[bool, str]:
as in _TEST_ENV.
See tests/rules/test_job_environment_prefix.py for examples of
incorrectly names environment variables.
incorrectly named environment variables.
"""
correct = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import Optional, Tuple, Union

from ..models.workflow import Workflow
from ..models.job import Job
from ..models.step import Step
from ..models.workflow import Workflow
from ..rule import Rule
from ..utils import LintLevels, Settings

Expand All @@ -20,7 +20,7 @@ def __init__(self, settings: Optional[Settings] = None) -> None:
Args:
settings:
A Settings object that contains any default, overriden, or custom settings
A Settings object that contains any default, overridden, or custom settings
required anywhere in the application.
"""
self.message = "name must capitalized"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""A Rule to enforce that a 'name' exists."""
"""A Rule to enforce that a 'name' key exists."""

from typing import Optional, Tuple, Union

Expand All @@ -10,7 +10,7 @@


class RuleNameExists(Rule):
"""Rule to enforce a 'name' exists for every object in GitHub Actions.
"""Rule to enforce a 'name' key exists for every object in GitHub Actions.
For pipeline run troubleshooting and debugging, it is helpful to have a
name to immediately identify a Workflow, Job, or Step while moving between
Expand All @@ -24,7 +24,7 @@ def __init__(self, settings: Optional[Settings] = None) -> None:
Args:
settings:
A Settings object that contains any default, overriden, or custom settings
A Settings object that contains any default, overridden, or custom settings
required anywhere in the application.
"""
self.message = "name must exist"
Expand Down
Loading

0 comments on commit 1c0c8f3

Please sign in to comment.