Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F83399082
ReleephRequestTypeaheadController.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
Mon, Sep 16, 21:46
Size
2 KB
Mime Type
text/x-php
Expires
Wed, Sep 18, 21:46 (2 d)
Engine
blob
Format
Raw Data
Handle
20817962
Attached To
rPH Phabricator
ReleephRequestTypeaheadController.php
View Options
<?php
final
class
ReleephRequestTypeaheadController
extends
PhabricatorTypeaheadDatasourceController
{
public
function
processRequest
()
{
$request
=
$this
->
getRequest
();
$query
=
$request
->
getStr
(
'q'
);
$repo_id
=
$request
->
getInt
(
'repo'
);
$since
=
$request
->
getInt
(
'since'
);
$limit
=
$request
->
getInt
(
'limit'
);
$now
=
time
();
$data
=
array
();
// Dummy instances used for getting connections, table names, etc.
$pr_commit
=
new
PhabricatorRepositoryCommit
();
$pr_commit_data
=
new
PhabricatorRepositoryCommitData
();
$conn
=
$pr_commit
->
establishConnection
(
'r'
);
$rows
=
queryfx_all
(
$conn
,
'SELECT
rc.phid as commitPHID,
rc.authorPHID,
rcd.authorName,
SUBSTRING(rcd.commitMessage, 1, 100) AS shortMessage,
rc.commitIdentifier,
rc.epoch
FROM %T rc
INNER JOIN %T rcd ON rcd.commitID = rc.id
WHERE repositoryID = %d
AND rc.epoch >= %d
AND (
rcd.commitMessage LIKE %~
OR
rc.commitIdentifier LIKE %~
)
ORDER BY rc.epoch DESC
LIMIT %d'
,
$pr_commit
->
getTableName
(),
$pr_commit_data
->
getTableName
(),
$repo_id
,
$since
,
$query
,
$query
,
$limit
);
foreach
(
$rows
as
$row
)
{
$full_commit_id
=
$row
[
'commitIdentifier'
];
$short_commit_id
=
substr
(
$full_commit_id
,
0
,
12
);
$first_line
=
$this
->
getFirstLine
(
$row
[
'shortMessage'
]);
$data
[]
=
array
(
$full_commit_id
,
$short_commit_id
,
$row
[
'authorName'
],
phabricator_format_relative_time
(
$now
-
$row
[
'epoch'
]),
$first_line
,
);
}
return
id
(
new
AphrontAjaxResponse
())
->
setContent
(
$data
);
}
/**
* Split either at the first new line, or a bunch of dashes.
*
* Really just a legacy from old Releeph Daemon commit messages where I used
* to say:
*
* Commit of FOO for BAR
* ------------
* This does X Y Z
*
*/
private
function
getFirstLine
(
$commit_message_fragment
)
{
static
$separators
=
array
(
'-------'
,
"
\n
"
);
$string
=
ltrim
(
$commit_message_fragment
);
$first_line
=
$string
;
foreach
(
$separators
as
$separator
)
{
if
(
$pos
=
strpos
(
$string
,
$separator
))
{
$first_line
=
substr
(
$string
,
0
,
$pos
);
break
;
}
}
return
$first_line
;
}
}
Event Timeline
Log In to Comment