Skip to content

Make the default action (and the logic contained inside it) easier to reuse #213

@grahamalama

Description

@grahamalama

These are some ideas I had to make reusing logic present in the default action easier:

Break up long methods so that they have fewer responsibilities

The goal here would be to make methods easier to override while still allowing action authors to reuse sensible default logic.

For example, the create_and_link_issue method:

  • creates an issue on Jira
  • checks if that issue is a duplicate. If is isn't:
  • links the Jira ticket to bugzilla
  • appends the Jira issue URL to the bugzilla bug

If an author wanted to do something else during the create_and_link_issue method, they'd probably have to copy + paste the whole method just to add their logic.

But if create_and_link_issue looked more like:

def create_and_link_issue(self, *args, **kwargs):
    issue = self.create_issue(...)
    is_dupe = self.check_if_duplicate(...)
    if is_dupe:
        return self.rollback_issue_creation(...)
    link_bug_response = self.link_bug_to_issue(...)
    link_issue_response = self.link_issue_to_bug(...)
    return True, {...}

it would be easier for an author to adapt this method to suit their needs, either by:

def create_and_link_issue(self, *args, **kwargs):
    response = super().create_and_link_issue(self, *args, **kwargs)
    additional_response = self.my_additional_thing(...)
    return True, {...}

or

def create_and_link_issue(self, *args, **kwargs):
    issue = self.create_issue(...)
    # we don't care about dupes
    link_bug_response = self.link_bug_to_issue(...)
    link_issue_response = self.link_issue_to_bug(...)
    additional_response = self.my_additional_thing(...)
    return True, {...}

Move more functions / methods to service module

Some of the logic we currently have in the default action would probably be better suited for the service module. This would help slim down methods in the default action, which would make reusing it easier. It would also make creating brand new actions easier.

These methods would probably know how to receive our models (mostly payloads) and do things with them. For instance:

def create_jira_issue_from_payload(payload, *args, **kwargs):
def update_assignee(payload, *args, **kwargs):
def update_status(payload, *args, **kwargs):

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions