Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P1182
blah.php
Active
Public
Actions
Authored by
hach-que
on Jun 18 2014, 12:38 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Flag For Later
Award Token
Tags
None
Referenced Files
F167838: blah.php
Jun 18 2014, 12:38 AM
2014-06-18 00:38:30 (UTC+0)
Subscribers
None
/**
* 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
();
}
}
Event Timeline
hach-que
edited the content of this paste.
(Show Details)
Jun 18 2014, 12:38 AM
2014-06-18 00:38:30 (UTC+0)
hach-que
changed the title of this paste from untitled to
blah.php
.
hach-que
updated the paste's language from
autodetect
to
autodetect
.
Log In to Comment