-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jira integration for release readiness
- Loading branch information
gitstart_bot
committed
Nov 20, 2024
1 parent
ef684e8
commit 1b4bc80
Showing
25 changed files
with
1,478 additions
and
7 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
class IntegrationListeners::JiraController < IntegrationListenerController | ||
using RefinedString | ||
|
||
INTEGRATION_CREATE_ERROR = "Failed to create the integration, please try again." | ||
|
||
def callback | ||
unless valid_state? | ||
redirect_to app_path(state_app), alert: INTEGRATION_CREATE_ERROR | ||
return | ||
end | ||
|
||
begin | ||
@integration = state_app.integrations.build(integration_params) | ||
@integration.providable = build_providable | ||
|
||
if @integration.providable.complete_access | ||
@integration.save! | ||
redirect_to app_path(state_app), | ||
notice: t("integrations.project_management.jira.integration_created") | ||
else | ||
@resources = @integration.providable.available_resources | ||
|
||
if @resources.blank? | ||
redirect_to app_integrations_path(state_app), | ||
alert: t("integrations.project_management.jira.no_organization") | ||
return | ||
end | ||
|
||
render "jira_integration/select_organization" | ||
end | ||
rescue => e | ||
Rails.logger.error("Failed to create Jira integration: #{e.message}") | ||
redirect_to app_integrations_path(state_app), | ||
alert: INTEGRATION_CREATE_ERROR | ||
end | ||
end | ||
|
||
def set_organization | ||
@integration = state_app.integrations.build(integration_params) | ||
@integration.providable = build_providable | ||
@integration.providable.cloud_id = params[:cloud_id] | ||
@integration.providable.code = params[:code] | ||
|
||
if @integration.save! | ||
@integration.providable.setup | ||
redirect_to app_path(@integration.integrable), | ||
notice: t("integrations.project_management.jira.integration_created") | ||
else | ||
@resources = @integration.providable.available_resources | ||
render "jira_integration/select_organization" | ||
end | ||
rescue => e | ||
Rails.logger.error("Failed to create Jira integration: #{e.message}") | ||
redirect_to app_integrations_path(state_app), | ||
alert: INTEGRATION_CREATE_ERROR | ||
end | ||
|
||
protected | ||
|
||
def providable_params | ||
super.merge( | ||
code: code, | ||
callback_url: callback_url | ||
) | ||
end | ||
|
||
private | ||
|
||
def callback_url | ||
host = request.host_with_port | ||
Rails.application.routes.url_helpers.jira_callback_url( | ||
host: host, | ||
protocol: request.protocol.gsub("://", "") | ||
) | ||
end | ||
|
||
def state | ||
@state ||= begin | ||
cleaned_state = params[:state].tr(" ", "+") | ||
JSON.parse(cleaned_state.decode).with_indifferent_access | ||
rescue ActiveSupport::MessageEncryptor::InvalidMessage => e | ||
Rails.logger.error "Invalid state parameter: #{e.message}" | ||
{} | ||
end | ||
end | ||
|
||
def error? | ||
params[:error].present? || state.empty? | ||
end | ||
|
||
def state_app | ||
@state_app ||= App.find(state[:app_id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
static targets = ["config", "filterDivider"] | ||
|
||
connect() { | ||
this.toggleConfigurations() | ||
this.toggleFilterDivider() | ||
} | ||
|
||
toggle(event) { | ||
this.toggleConfigurations() | ||
this.toggleFilterDivider() | ||
} | ||
|
||
toggleConfigurations() { | ||
const configs = document.querySelectorAll('.project-config') | ||
configs.forEach(config => { | ||
const projectKey = config.dataset.project | ||
const checkbox = document.querySelector(`#project_${projectKey}`) | ||
if (checkbox) { | ||
config.style.display = checkbox.checked ? 'block' : 'none' | ||
} | ||
}) | ||
} | ||
|
||
toggleFilterDivider() { | ||
const anyProjectSelected = Array.from(document.querySelectorAll('input[name^="app_config[jira_config][selected_projects]"]')) | ||
.some(checkbox => checkbox.checked) | ||
|
||
if (this.hasFilterDividerTarget) { | ||
this.filterDividerTarget.style.display = anyProjectSelected ? 'block' : 'none' | ||
this.filterDividerTarget.classList.add('border-t') | ||
this.filterDividerTarget.classList.add('border-b') | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
static targets = ["content"] | ||
|
||
toggle(event) { | ||
this.contentTarget.style.display = event.target.checked ? "block" : "none" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
static targets = ["template", "container", "filter"] | ||
|
||
add(event) { | ||
event.preventDefault() | ||
const content = this.templateTarget.innerHTML.replace(/__INDEX__/g, this.filterTargets.length) | ||
this.containerTarget.insertAdjacentHTML("beforeend", content) | ||
} | ||
|
||
remove(event) { | ||
event.preventDefault() | ||
const filter = event.target.closest("[data-release-filters-target='filter']") | ||
filter.remove() | ||
} | ||
} |
Oops, something went wrong.