Skip to content

Commit

Permalink
Merge pull request #26 from bb-io/develop
Browse files Browse the repository at this point in the history
Added optional manual input to JIRA
  • Loading branch information
vitalii-bezuhlyi authored Aug 20, 2024
2 parents af487dc + 5d7d1ac commit 337829a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Apps.Jira/Apps.Jira.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>12</LangVersion>
<Product>Jira</Product>
<Description>Issue tracking</Description>
<Version>2.2.5</Version>
<Version>2.2.6</Version>
<AssemblyName>Apps.Jira</AssemblyName>
</PropertyGroup>
<ItemGroup>
Expand Down
14 changes: 10 additions & 4 deletions Apps.Jira/DataSourceHandlers/LabelDataHandler.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
using Apps.Jira.Dtos;
using Apps.Jira.Models.Requests;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dynamic;
using Blackbird.Applications.Sdk.Common.Invocation;
using RestSharp;

namespace Apps.Jira.DataSourceHandlers;

public class LabelDataHandler(InvocationContext invocationContext)
public class LabelDataHandler(InvocationContext invocationContext, [ActionParameter] LabelsOptionalInput input)
: JiraInvocable(invocationContext), IAsyncDataSourceHandler
{
public async Task<Dictionary<string, string>> GetDataAsync(DataSourceContext context, CancellationToken cancellationToken)
{
if (input.Labels is not null)
{
throw new InvalidOperationException("You can't use both manual and dropdown labels at the same time.");
}

const int maxResultsPerPage = 1000;
int startAt = 0;
bool isLast = false;
var startAt = 0;
var isLast = false;

var allLabels = new List<string>();

while (!isLast)
{
var request = new JiraRequest($"/label?startAt={startAt}&maxResults={maxResultsPerPage}", Method.Get);
Expand Down
5 changes: 4 additions & 1 deletion Apps.Jira/Models/Requests/LabelsOptionalInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Apps.Jira.Models.Requests;

public class LabelsOptionalInput
{
[Display("Labels", Description = "Use this input if you want to filter results based on labels")]
[Display("Labels (manual)", Description = "Manually enter labels to filter results without using a dropdown. Use this input if you want to filter results based on labels")]
public IEnumerable<string>? Labels { get; set; }

[Display("Labels (dropdown selection)", Description = "Select labels from a dropdown to filter results. Use this input if you want to filter results based on labels"), DataSource(typeof(LabelDataHandler))]
public IEnumerable<string>? LabelsDropDown { get; set; }
}
2 changes: 1 addition & 1 deletion Apps.Jira/Webhooks/IssueWebhooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task<WebhookResponse<IssueResponse>> OnIssueUpdated(WebhookRequest
[WebhookParameter] LabelsOptionalInput labels)
{
var payload = DeserializePayload(request);

if ((project.ProjectKey is not null && !project.ProjectKey.Equals(payload.Issue.Fields.Project.Key)) ||
(issue.IssueKey is not null && !issue.IssueKey.Equals(payload.Issue.Key)))
return new WebhookResponse<IssueResponse>
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ Note: this app currently supports only short text (plain text only) custom field
- **On file attached to issue** is triggered when a file is attached to an issue. If you want a bird to be triggered when a file is attached to specific issue, specify the issue parameter. Otherwise, you can specify project parameter if you are interested in specific project's issues.
- **On issue status changed** is triggered when issue status is changed. If you want a bird to be triggered when specific issue's status is changed, specify the issue parameter. Otherwise, you can specify project parameter if you are interested in specific project's issues. You can also limit the event to trigger only on certain statusses.

## Optional inputs

We may provide two options for inputting one property to filter results:

1. **Manual**:
- **Description**: Allows the user to manually enter value without the assistance of a dropdown list.
- **Use Case**: This option is ideal when the user knows the exact value they want to use or when the dropdown may not be effective due to the large number of values available through the API.

2. **Dropdown selection**:
- **Description**: Allows the user to select a value from a dropdown list.
- **Use Case**: This option is suitable when there are fewer labels, making it convenient for users to select from a predefined list. However, this approach can be less effective if the number of labels is very large, potentially leading to timeout errors during data retrieval.

### Why do we use this approach?

This approach ensures flexibility by providing two methods for inputs, accommodating both situations where the user may need to manually enter specific values and where selecting from a predefined list is more practical. The 'manual' option is particularly useful when dealing with a large number of labels, which could otherwise lead to performance issues when retrieving values from the API.

## Example

![example](Images/README/example.png)
Expand Down

0 comments on commit 337829a

Please sign in to comment.