Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F167838
blah.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
hach-que
Jun 18 2014, 12:38 AM
2014-06-18 00:38:30 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
blah.php
View Options
/**
* Creates a new release and release states from a release system.
*/
public
static
function
initializeFrom
(
PhabricatorUser
$viewer
,
PipelineReleaseSystem
$system
)
{
// Create the release.
$release
=
id
(
new
PipelineRelease
())
->
setReleaseSystemPHID
(
$system
->
getPHID
())
->
setReleaseBuildPHID
(
null
)
->
setApprovalBuildPHID
(
null
)
->
setFailureBuildPHID
(
null
)
->
save
();
$lines
=
id
(
new
PipelineReleaseLineQuery
())
->
setViewer
(
$viewer
)
->
withReleaseSystemPHIDs
(
array
(
$system
->
getPHID
()))
->
needRepositories
(
true
)
->
needCreationBuildPlans
(
true
)
->
execute
();
// Create the release states.
foreach
(
$lines
as
$line
)
{
$state
=
id
(
new
PipelineReleaseState
())
->
setReleasePHID
(
$release
->
getPHID
())
->
setReleaseLinePHID
(
$line
->
getPHID
());
// Get end commit (current commit for a release line).
$refs
=
id
(
new
ConduitCall
(
'diffusion.resolverefs'
,
array
(
'refs'
=>
array
(
$line
->
getBranchName
()),
'callsign'
=>
$line
->
getRepository
()->
getCallsign
()
)))
->
setUser
(
$viewer
)
->
execute
();
$candidate_refs
=
$refs
[
$line
->
getBranchName
()];
$end_ref
=
null
;
foreach
(
$candidate_refs
as
$candidate_ref
)
{
if
(
$candidate_ref
[
'type'
]
===
'commit'
)
{
$end_ref
=
$candidate_ref
[
'identifier'
];
}
}
if
(
$end_ref
===
null
)
{
throw
new
Exception
(
pht
(
"Unable to resolve reference called '%s'"
,
$line
->
getBranchName
()));
}
// TODO Get start commit.
$start_ref
=
null
;
// Set and increment release counter.
$state
->
setVersion
(
self
::
formatVersion
(
$viewer
,
$line
->
getReleaseCounter
(),
$line
->
getVersionFormat
()));
// Increment line release counter only if there are new commits.
if
(
$start_ref
!==
$end_ref
)
{
$line
->
setReleaseCounter
(
$line
->
getReleaseCounter
()
+
1
);
$line
->
save
();
}
// TODO Technically N+1, but it's not expected there'll be more than
// a few release lines for a release system anyway.
$commit_phid
=
id
(
new
DiffusionCommitQuery
())
->
setViewer
(
$viewer
)
->
withIdentifiers
(
array
(
$end_ref
))
->
executeOne
()
->
getPHID
();
// TODO: If start and end are same, look up the creation build for the
// previous release state that contained new commits and use that
// instead.
// Kick off the creation build for the state.
$buildable
=
HarbormasterBuildable
::
createOrLoadExisting
(
$viewer
,
$commit_phid
,
$line
->
getRepository
()->
getPHID
());
$build
=
$buildable
->
applyPlan
(
$line
->
getCreationBuildPlan
());
// Save the state.
$state
->
setStartCommitIdentifier
(
$start_ref
);
$state
->
setEndCommitIdentifier
(
$end_ref
);
$state
->
setCreationBuildPHID
(
$build
->
getPHID
());
$state
->
save
();
}
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/gz/6o/b5u4in2gmhsr4ch7
Default Alt Text
blah.php (2 KB)
Attached To
Mode
P1182 blah.php
Attached
Detach File
Event Timeline
Log In to Comment