Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1731798
AddSubscribersFromJIRAIssuesHeraldCustomAction.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
avivey
Jul 21 2016, 9:54 PM
2016-07-21 21:54:04 (UTC+0)
Size
3 KB
Referenced Files
None
Subscribers
None
AddSubscribersFromJIRAIssuesHeraldCustomAction.php
View Options
<?php
final
class
AddSubscribersFromJIRAIssuesHeraldCustomAction
extends
HeraldAction
{
const
ACTIONCONST
=
'jira:add-cc'
;
public
function
supportsRuleType
(
$rule_type
)
{
return
(
$rule_type
!=
HeraldRuleTypeConfig
::
RULE_TYPE_PERSONAL
);
}
public
function
supportsObject
(
$object
)
{
return
$object
instanceof
DifferentialRevision
;
}
public
function
getHeraldActionName
()
{
return
'Add Subscribers from JIRA issues'
;
}
public
function
getHeraldActionStandardType
()
{
return
self
::
STANDARD_NONE
;
}
public
function
applyEffect
(
$object
,
HeraldEffect
$effect
)
{
phlog
(
'applying jira effect'
);
$rule
=
$effect
->
getRule
();
$viewer
=
PhabricatorUser
::
getOmnipotentUser
();
$adapter
=
$this
->
getAdapter
();
$provider
=
PhabricatorJIRAAuthProvider
::
getJIRAProvider
();
if
(!
$provider
)
{
return
;
}
$jira_issue_phids
=
PhabricatorEdgeQuery
::
loadDestinationPHIDs
(
$object
->
getPHID
(),
PhabricatorJiraIssueHasObjectEdgeType
::
EDGECONST
);
if
(!
$jira_issue_phids
)
{
return
;
}
$xobjs
=
id
(
new
DoorkeeperExternalObjectQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
$jira_issue_phids
)
->
execute
();
$xobjs
=
mgroup
(
$xobjs
,
'getApplicationDomain'
);
if
(!
$xobjs
)
{
return
;
}
$cc_phids
=
array
();
foreach
(
$xobjs
as
$domain
=>
$xobj_list
)
{
$account
=
id
(
new
PhabricatorExternalAccountQuery
())
->
setViewer
(
$viewer
)
->
withUserPHIDs
(
array
(
$rule
->
getAuthorPHID
()))
// TODO?
->
withAccountTypes
(
array
(
$provider
->
getProviderType
()))
->
withAccountDomains
(
array
(
$domain
))
->
requireCapabilities
(
array
(
PhabricatorPolicyCapability
::
CAN_VIEW
,
PhabricatorPolicyCapability
::
CAN_EDIT
,
))
->
executeOne
();
$futures
=
array
();
foreach
(
$xobj_list
as
$key
=>
$xobj
)
{
$id
=
$xobj
->
getObjectID
();
$futures
[
$key
]
=
$provider
->
newJIRAFuture
(
$account
,
'rest/api/2/issue/'
.
phutil_escape_uri
(
$id
).
'/watchers'
,
'GET'
);
}
$usernames
=
array
();
foreach
(
new
FutureIterator
(
$futures
)
as
$key
=>
$future
)
{
try
{
$result
=
$future
->
resolveJSON
();
$list
=
idx
(
$result
,
'watchers'
,
array
());
foreach
(
$list
as
$watcher
)
{
$usernames
[]
=
strtolower
(
idx
(
$watcher
,
'key'
,
''
));
}
}
catch
(
Exception
$ex
)
{
phlog
(
$ex
);
}
}
$externals
=
id
(
new
PhabricatorExternalAccountQuery
())
->
setViewer
(
$viewer
)
->
withAccountTypes
(
array
(
$provider
->
getProviderType
()))
->
withAccountIDs
(
$usernames
)
->
withAccountDomains
(
array
(
$domain
))
->
execute
();
$cc_phids
[]
=
mpull
(
$externals
,
'getUserPHID'
);
}
$cc_phids
=
array_mergev
(
$cc_phids
);
if
(!
$cc_phids
)
{
return
;
}
$xaction
=
$adapter
->
newTransaction
()
->
setTransactionType
(
PhabricatorTransactions
::
TYPE_SUBSCRIBERS
)
->
setNewValue
(
array
(
'+'
=>
$cc_phids
,
));
$adapter
->
queueTransaction
(
$xaction
);
$this
->
logEffect
(
'do.subscribe'
,
$cc_phids
);
}
public
function
getActionEffectMap
()
{
return
array
(
'do.subscribe'
=>
array
(
'icon'
=>
'fa-envelope'
,
'color'
=>
'green'
,
'name'
=>
pht
(
'Add subscribers from JIRA'
),
),
);
}
public
function
renderActionDescription
(
$value
)
{
return
pht
(
'Add Subscribers from JIRA issues.'
);
}
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
211650
Default Alt Text
AddSubscribersFromJIRAIssuesHeraldCustomAction.php (3 KB)
Attached To
Mode
P2001 AddSubscribersFromJIRAIssuesHeraldCustomAction.php
Attached
Detach File
Event Timeline
Log In to Comment