Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101208061
PhabricatorRepositorySearchEngine.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Feb 6, 19:52
Size
8 KB
Mime Type
text/x-php
Expires
Sat, Feb 8, 19:52 (2 d)
Engine
blob
Format
Raw Data
Handle
24112889
Attached To
rPH Phabricator
PhabricatorRepositorySearchEngine.php
View Options
<?php
final
class
PhabricatorRepositorySearchEngine
extends
PhabricatorApplicationSearchEngine
{
public
function
getResultTypeDescription
()
{
return
pht
(
'Repositories'
);
}
public
function
getApplicationClassName
()
{
return
'PhabricatorDiffusionApplication'
;
}
public
function
newQuery
()
{
return
id
(
new
PhabricatorRepositoryQuery
())
->
needProjectPHIDs
(
true
)
->
needCommitCounts
(
true
)
->
needMostRecentCommits
(
true
)
->
needProfileImage
(
true
);
}
protected
function
buildCustomSearchFields
()
{
return
array
(
id
(
new
PhabricatorSearchStringListField
())
->
setLabel
(
pht
(
'Callsigns'
))
->
setKey
(
'callsigns'
),
id
(
new
PhabricatorSearchStringListField
())
->
setLabel
(
pht
(
'Short Names'
))
->
setKey
(
'shortNames'
),
id
(
new
PhabricatorSearchSelectField
())
->
setLabel
(
pht
(
'Status'
))
->
setKey
(
'status'
)
->
setOptions
(
$this
->
getStatusOptions
()),
id
(
new
PhabricatorSearchSelectField
())
->
setLabel
(
pht
(
'Hosted'
))
->
setKey
(
'hosted'
)
->
setOptions
(
$this
->
getHostedOptions
()),
id
(
new
PhabricatorSearchCheckboxesField
())
->
setLabel
(
pht
(
'Types'
))
->
setKey
(
'types'
)
->
setOptions
(
PhabricatorRepositoryType
::
getAllRepositoryTypes
()),
id
(
new
PhabricatorSearchStringListField
())
->
setLabel
(
pht
(
'URIs'
))
->
setKey
(
'uris'
)
->
setDescription
(
pht
(
'Search for repositories by clone/checkout URI.'
)),
// c4science custo
// Search repo by author
id
(
new
PhabricatorUsersSearchField
())
->
setLabel
(
pht
(
'Author'
))
->
setKey
(
'authorPHIDs'
)
->
setAliases
(
array
(
'author'
,
'authors'
)),
);
}
protected
function
buildQueryFromParameters
(
array
$map
)
{
$query
=
$this
->
newQuery
();
// c4science custo
// Search repo by author
if
(
$map
[
'authorPHIDs'
])
{
$viewer
=
$this
->
requireViewer
();
$repo_transaction
=
id
(
new
PhabricatorRepositoryTransactionQuery
())
->
setViewer
(
$viewer
)
->
withAuthorPHIDs
(
$map
[
'authorPHIDs'
])
->
withTransactionTypes
(
array
(
PhabricatorTransactions
::
TYPE_CREATE
))
->
execute
();
if
(!
empty
(
$repo_transaction
))
{
$repo_phids
=
mpull
(
$repo_transaction
,
'getObjectPHID'
);
}
if
(!
empty
(
$repo_phids
))
{
$query
->
withPHIDs
(
$repo_phids
);
}
else
{
// Force the query to have no result
$query
->
withPHIDs
(
array
(
NULL
));
// If there's no result here, no point of continuing to filter
return
$query
;
}
}
if
(
$map
[
'callsigns'
])
{
$query
->
withCallsigns
(
$map
[
'callsigns'
]);
}
if
(
$map
[
'shortNames'
])
{
$query
->
withSlugs
(
$map
[
'shortNames'
]);
}
if
(
$map
[
'status'
])
{
$status
=
idx
(
$this
->
getStatusValues
(),
$map
[
'status'
]);
if
(
$status
)
{
$query
->
withStatus
(
$status
);
}
}
if
(
$map
[
'hosted'
])
{
$hosted
=
idx
(
$this
->
getHostedValues
(),
$map
[
'hosted'
]);
if
(
$hosted
)
{
$query
->
withHosted
(
$hosted
);
}
}
if
(
$map
[
'types'
])
{
$query
->
withTypes
(
$map
[
'types'
]);
}
if
(
$map
[
'uris'
])
{
$query
->
withURIs
(
$map
[
'uris'
]);
}
return
$query
;
}
protected
function
getURI
(
$path
)
{
return
'/diffusion/'
.
$path
;
}
protected
function
getBuiltinQueryNames
()
{
// C4science customization
$names
=
array
();
$viewer
=
$this
->
requireViewer
();
if
(
$viewer
->
getUsername
())
{
$names
+=
array
(
'user'
=>
pht
(
'My Repositories'
),
'project'
=>
pht
(
'Project Repositories'
),
);
}
else
{
$names
+=
array
(
'active'
=>
pht
(
'Active Repositories'
),
);
}
$names
+=
array
(
'all'
=>
pht
(
'All Repositories'
),
);
// end of c4science customization
return
$names
;
}
public
function
buildSavedQueryFromBuiltin
(
$query_key
)
{
$query
=
$this
->
newSavedQuery
();
$query
->
setQueryKey
(
$query_key
);
switch
(
$query_key
)
{
case
'user'
:
// c4science custo
return
$query
->
setParameter
(
'status'
,
'open'
)
->
setParameter
(
'authorPHIDs'
,
array
(
'viewer()'
));
case
'project'
:
// c4science custo
return
$query
->
setParameter
(
'status'
,
'open'
)
->
setParameter
(
'projectPHIDs'
,
array
(
'viewerprojects()'
));
case
'active'
:
return
$query
->
setParameter
(
'status'
,
'open'
);
case
'all'
:
return
$query
;
}
return
parent
::
buildSavedQueryFromBuiltin
(
$query_key
);
}
private
function
getStatusOptions
()
{
return
array
(
''
=>
pht
(
'Active and Inactive Repositories'
),
'open'
=>
pht
(
'Active Repositories'
),
'closed'
=>
pht
(
'Inactive Repositories'
),
);
}
private
function
getStatusValues
()
{
return
array
(
''
=>
PhabricatorRepositoryQuery
::
STATUS_ALL
,
'open'
=>
PhabricatorRepositoryQuery
::
STATUS_OPEN
,
'closed'
=>
PhabricatorRepositoryQuery
::
STATUS_CLOSED
,
);
}
private
function
getHostedOptions
()
{
return
array
(
''
=>
pht
(
'Hosted and Remote Repositories'
),
'phabricator'
=>
pht
(
'Hosted Repositories'
),
'remote'
=>
pht
(
'Remote Repositories'
),
);
}
private
function
getHostedValues
()
{
return
array
(
''
=>
PhabricatorRepositoryQuery
::
HOSTED_ALL
,
'phabricator'
=>
PhabricatorRepositoryQuery
::
HOSTED_PHABRICATOR
,
'remote'
=>
PhabricatorRepositoryQuery
::
HOSTED_REMOTE
,
);
}
protected
function
getRequiredHandlePHIDsForResultList
(
array
$repositories
,
PhabricatorSavedQuery
$query
)
{
return
array_mergev
(
mpull
(
$repositories
,
'getProjectPHIDs'
));
}
protected
function
renderResultList
(
array
$repositories
,
PhabricatorSavedQuery
$query
,
array
$handles
)
{
assert_instances_of
(
$repositories
,
'PhabricatorRepository'
);
$viewer
=
$this
->
requireViewer
();
$list
=
new
PHUIObjectItemListView
();
foreach
(
$repositories
as
$repository
)
{
$id
=
$repository
->
getID
();
$item
=
id
(
new
PHUIObjectItemView
())
->
setUser
(
$viewer
)
->
setObject
(
$repository
)
->
setHeader
(
$repository
->
getName
())
->
setObjectName
(
$repository
->
getMonogram
())
->
setHref
(
$repository
->
getURI
())
->
setImageURI
(
$repository
->
getProfileImageURI
());
$commit
=
$repository
->
getMostRecentCommit
();
if
(
$commit
)
{
$commit_link
=
phutil_tag
(
'a'
,
array
(
'href'
=>
$commit
->
getURI
(),
),
pht
(
'%s: %s'
,
$commit
->
getLocalName
(),
$commit
->
getSummary
()));
$item
->
setSubhead
(
$commit_link
);
$item
->
setEpoch
(
$commit
->
getEpoch
());
}
$item
->
addIcon
(
'none'
,
PhabricatorRepositoryType
::
getNameForRepositoryType
(
$repository
->
getVersionControlSystem
()));
$size
=
$repository
->
getCommitCount
();
if
(
$size
)
{
$history_uri
=
$repository
->
generateURI
(
array
(
'action'
=>
'history'
,
));
$item
->
addAttribute
(
phutil_tag
(
'a'
,
array
(
'href'
=>
$history_uri
,
),
pht
(
'%s Commit(s)'
,
new
PhutilNumber
(
$size
))));
}
else
{
$item
->
addAttribute
(
pht
(
'No Commits'
));
}
$project_handles
=
array_select_keys
(
$handles
,
$repository
->
getProjectPHIDs
());
if
(
$project_handles
)
{
$item
->
addAttribute
(
id
(
new
PHUIHandleTagListView
())
->
setSlim
(
true
)
->
setHandles
(
$project_handles
));
}
if
(!
$repository
->
isTracked
())
{
$item
->
setDisabled
(
true
);
$item
->
addIcon
(
'disable-grey'
,
pht
(
'Inactive'
));
}
else
if
(
$repository
->
isImporting
())
{
$item
->
addIcon
(
'fa-clock-o indigo'
,
pht
(
'Importing...'
));
}
$list
->
addItem
(
$item
);
}
$result
=
new
PhabricatorApplicationSearchResultView
();
$result
->
setObjectList
(
$list
);
$result
->
setNoDataString
(
pht
(
'No repositories found for this query.'
));
return
$result
;
}
protected
function
willUseSavedQuery
(
PhabricatorSavedQuery
$saved
)
{
$project_phids
=
$saved
->
getParameter
(
'projectPHIDs'
,
array
());
$old
=
$saved
->
getParameter
(
'projects'
,
array
());
foreach
(
$old
as
$phid
)
{
$project_phids
[]
=
$phid
;
}
$any
=
$saved
->
getParameter
(
'anyProjectPHIDs'
,
array
());
foreach
(
$any
as
$project
)
{
$project_phids
[]
=
'any('
.
$project
.
')'
;
}
$saved
->
setParameter
(
'projectPHIDs'
,
$project_phids
);
}
protected
function
getNewUserBody
()
{
$new_button
=
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setText
(
pht
(
'New Repository'
))
->
setHref
(
'/diffusion/edit/'
)
->
setColor
(
PHUIButtonView
::
GREEN
);
$icon
=
$this
->
getApplication
()->
getIcon
();
$app_name
=
$this
->
getApplication
()->
getName
();
$view
=
id
(
new
PHUIBigInfoView
())
->
setIcon
(
$icon
)
->
setTitle
(
pht
(
'Welcome to %s'
,
$app_name
))
->
setDescription
(
pht
(
'Import, create, or just browse repositories in Diffusion.'
))
->
addAction
(
$new_button
);
return
$view
;
}
}
Event Timeline
Log In to Comment