-
Notifications
You must be signed in to change notification settings - Fork 16
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
Jan 8, 2025
1 parent
0b694c9
commit 7b12725
Showing
28 changed files
with
1,484 additions
and
6 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 |
17 changes: 17 additions & 0 deletions
17
app/javascript/controllers/domain/release_filters_controller.js
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-domain--release-filters-target='filter']") | ||
filter.remove() | ||
} | ||
} |
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,5 @@ | ||
export function toggleDisplay(target, condition) { | ||
if (target) { | ||
target.style.display = condition ? "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,37 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import { toggleDisplay } from "./helper" | ||
|
||
export default class extends Controller { | ||
static targets = [ "projectCheckbox", "config", "filterDivider"] | ||
|
||
connect() { | ||
this.toggleConfigurations() | ||
this.toggleFilterDivider() | ||
} | ||
|
||
toggle() { | ||
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) { | ||
toggleDisplay(config, checkbox.checked) | ||
} | ||
}) | ||
} | ||
|
||
toggleFilterDivider() { | ||
const anyProjectSelected = this.projectCheckboxTargets.some(checkbox => checkbox.checked) | ||
|
||
if (this.hasFilterDividerTarget) { | ||
toggleDisplay(this.filterDividerTarget, anyProjectSelected) | ||
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,10 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import { toggleDisplay } from "./helper" | ||
|
||
export default class extends Controller { | ||
static targets = ["content"] | ||
|
||
toggle(event) { | ||
toggleDisplay(this.contentTarget, event.target.checked) | ||
} | ||
} |
Oops, something went wrong.