Extending using Custom Forms and Issue Ops Actions
This comprehensive guide will walk you through the process of creating custom forms that render in your Dev Central dashboard and setting up custom actions triggered by those forms.
By following this guide, you can create custom forms that render in your Dev Central dashboard and set up custom actions triggered by those forms. This approach allows you to extend the functionality of your sfops workflow to meet your specific project needs while leveraging the power of the sfops issueAnalyzer to process and utilize form data efficiently.
Remember that custom forms and actions should be designed with your team's specific workflows and requirements in mind. Regularly gather feedback from users and iterate on your custom forms and actions to ensure they continue to meet your team's evolving needs.
Creating a Custom Form
For self-managed instances, please create the forms yaml file in dashboard/_forms in your 'sfops' repository
Create a new YAML file in the
_forms
directory of your dev central repository. The file name will be used as the form identifier, so choose a descriptive name (e.g.,request-custom-action.yml
).Define the form structure in the YAML file using the following syntax:
Customize the form fields based on your requirements. Here are some commonly used field types and their behaviors:
input
: A single-line text input field. You can specify validations likerequired
to make the field mandatory.textarea
: A multi-line text input field for longer descriptions or comments.dropdown
: A dropdown menu with predefined options. You can specify theoptions
array to define the available choices.checkboxes
: A set of checkboxes allowing multiple selections. Each checkbox is defined within theoptions
array.select
: A dropdown menu with support for multiple selections. Theoptions
array defines the available choices, and you can group related options using theoptgroup
element.hiddenInput
: A hidden input field that is not visible to the user but can store predefined values.
Special Field IDs and Dynamic Options
In addition to the standard form fields, you can leverage special field IDs to populate form options dynamically based on external data sources. This allows for more flexible and data-driven form configurations. Here are some special field IDs you can use:
tag
field:Use the
tag
field ID to populate options based on available tags from thescratchOrgStatus.json
file.The field type will be automatically set to
dropdown
.Example:
sourceSB
field:Use the
sourceSB
field ID to populate options based on snapshot environments from theenvInfos.json
file.The field type will be automatically set to
dropdown
.Example:
sourceBranch
field:Use the
sourceBranch
field ID to populate options based on available branches from thebranches.json
file.The field type will be automatically set to
dropdown
.Example:
envs
field:Use the
envs
field ID to populate options based on environments fromenvInfos.json
, available developer sandboxes fromdeveloperSandboxes.json
, and available CI sandboxes fromciSandboxes.json
.The field type will be automatically set to
select
for multi-select functionality.Options will be grouped based on their type (e.g., "Developer", "Review") using the
optgroup
element.Example:
domain
field:Use the
domain
field ID to populate options based on available domains from thedomains.json
file.The field type will be automatically set to
dropdown
.Example:
By utilizing these special field IDs, you can create dynamic form fields that adapt to your project's specific data and configurations.
Creating a Custom Action
Create a new workflow file (e.g.,
custom-action-workflow.yml
) in the.github/workflows
directory of your project repository.Use the following template as a starting point for your custom action workflow:
Customize the workflow:
a. In the
on
section, the workflow is triggered when issues are opened or reopened. You can adjust this as needed.b. In the
analyze_issue
job:Replace
your-custom-form-id
in theinclude_issues
parameter with the ID of your custom form (the filename without the .yml extension).This job uses the
issueAnalyzer
action to determine if the issue is related to your custom form and extracts the form data.In the
outputs
section, define all the form fields and metadata you want to make available to subsequent jobs. Each output should correspond to a field in your form or metadata provided by the issueAnalyzer.
c. In the
execute_custom_action
job:This job only runs if the issue is identified as a custom form submission (
sfops_issue == 'true'
).You can directly access all form fields and metadata defined in the
outputs
of theanalyze_issue
job usingneeds.analyze_issue.outputs.<field_name>
.
d. Understanding the issueAnalyzer output: The issueAnalyzer processes the form data and makes it available as outputs. Here's how the data is structured:
sfops_issue
: A boolean value indicating whether the issue is a valid SFOps issue (based on include/exclude rules).Individual form fields: Each form field is available as a separate output with the prefix
sfops_issue_
.Metadata: Additional information like
issueNumber
,repoOwner
,repoName
, andissueCreator
are also available as outputs.
e. Accessing and using form data in your custom action:
You can access the form data in your custom action steps using the
needs
context. Here's an example of how to use the parsed data:This example demonstrates how to access various form fields and metadata directly from the job outputs.
Adjust the permissions and authentication as needed for your specific use case.
Commit and push the changes to your project repository.
How the issueAnalyzer Works
The issueAnalyzer is a crucial component in processing custom forms. Here's an overview of its functionality:
It fetches the issue details using the provided issue number, repository owner, and repository name.
It looks for a JSON payload in the issue body, which is typically enclosed in HTML comments (
<!-- -->
).If a valid JSON payload is found, it processes the data and sets various outputs:
sfops_issue
: Set to "true" if the issue is a valid SFOps issue, "false" otherwise.Individual form fields: Each field from the form is set as a separate output with the prefix
sfops_issue_
.
It adds some additional metadata as outputs:
sfops_issue_issueNumber
: The number of the current issue.sfops_issue_repoOwner
: The owner of the repository.sfops_issue_repoName
: The name of the repository.sfops_issue_issueCreator
: The GitHub username of the person who created the issue.
If the
envs
field is not present in the form data, it defaults to["devhub"]
.The analyzer respects the
include_issues
andexclude_issues
inputs to determine whether an issue should be processed or not.
By leveraging the issueAnalyzer, your custom action can easily access and use the form data submitted by users, allowing you to create powerful and flexible workflows tailored to your specific needs.
Best Practices
Keep your custom forms focused and concise, collecting only the necessary information.
Use meaningful labels and descriptions for form fields to guide users.
Leverage dynamic options when possible to reduce manual maintenance of form options.
In your custom action workflow, add appropriate error handling and logging.
Consider adding status checks or notifications to keep users informed about the progress of their request.
Regularly review and update your custom forms and actions to ensure they remain relevant and efficient.
Use the
include_issues
parameter in the issueAnalyzer step to ensure only relevant issues trigger your custom action.When processing form data, always validate inputs to ensure data integrity and security.
Utilize the metadata provided by the issueAnalyzer (such as
issue_creator
andrepo_name
) to add context to your custom actions.If your custom action involves sensitive operations, consider adding approval steps or additional security checks.
Define all necessary form fields and metadata as outputs in the
analyze_issue
job to make them easily accessible in subsequent jobs.Use meaningful names for your outputs to make the workflow more readable and maintainable.
Last updated