Skip to content

Update Zendesk when Linear issue changes #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions lib/Synergy/Reactor/LinearNotification.pm
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,53 @@ has name => (
default => 'lin',
);

has zendesk => (
is => 'ro',
isa => 'Zendesk::Client',
default => sub ($self) {
return Synergy::Reactor::Zendesk->zendesk_client;
},
lazy => 1,
);

sub linear_update_zendesk ($payload) {
my $issue_id = $payload->{data}{issueId};
my $issue = $self->linear->do_query(
q[ query Issue {
issue(id: $issue_id) {
attachments { nodes { url } }
labels { nodes { name } }
}
}])->get;

my $has_escalation_label = grep {
lc $_{name} eq lc $self->escalation_label_name
} $issue->{data}{issue}{labels}{nodes}->@*;

my @zendesk_url = grep {
$_{url} =~ /.*fastmail\.help\/agent\/tickets\/\d*/
} $issue->{data}{issue}{attachments}{nodes}->@*;

if ($has_escalation_label && @zendesk_url) {
$zendesk_url[0] =~ /.*\/(\d*)/;

$self->zendesk->ticket_api->add_comment_to_ticket_f($1, {
body => "Issue updated with a comment: $payload->{url}",
public => \0,
})->else(sub ($err, @) {
$Logger->log([ "something went wrong posting to Zendesk: %s", $err ]);
return Future->done;
})->retain;

$self->zendesk->ticket_api->update_by_zendesk_id_f($1, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if these two updates can possibly compete/block each other? It might be worth it to chain the status change to open once the add_comment_to_ticket finishes

status => "open",
})->else(sub ($err, @) {
$Logger->log([ "something went wrong changing the zendesk ticket status: %s", $err ]);
return Future->done;
})->retain;
}
}

sub http_app ($self, $env) {
my $req = Plack::Request->new($env);

Expand All @@ -104,6 +151,7 @@ sub http_app ($self, $env) {
return [ "200", [], [ '{"bad":"json"}' ] ];
}

# Notify in slack if issue is escalated
if ($self->escalation_channel_name && $self->escalation_address) {
if (my $channel = $self->hub->channel_named($self->escalation_channel_name)) {

Expand Down Expand Up @@ -171,6 +219,14 @@ sub http_app ($self, $env) {
}
}

# Action Zendesk ticket if comments are made on linear issues
my $made_comment = $payload->{type} eq 'Issue comments'
&& $payload->{action} eq 'create';

if ($made_comment) {
linear_update_zendesk($payload);
}

return [ "200", [], [ '{"o":"k"}' ] ];
}

Expand Down