11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2025 Adobe
4+ * All Rights Reserved .
55 */
66namespace Magento \NewRelicReporting \Console \Command ;
77
8+ use Magento \Framework \Exception \LocalizedException ;
89use Symfony \Component \Console \Command \Command ;
910use Symfony \Component \Console \Input \InputInterface ;
1011use Symfony \Component \Console \Output \OutputInterface ;
1112use Symfony \Component \Console \Input \InputArgument ;
13+ use Symfony \Component \Console \Input \InputOption ;
14+ use Symfony \Component \Console \Helper \Table ;
15+ use Magento \NewRelicReporting \Model \Config ;
1216use Magento \NewRelicReporting \Model \Apm \DeploymentsFactory ;
1317use Magento \NewRelicReporting \Model \ServiceShellUser ;
1418
@@ -17,27 +21,34 @@ class DeployMarker extends Command
1721 /**
1822 * @var DeploymentsFactory
1923 */
20- private $ deploymentsFactory ;
24+ private DeploymentsFactory $ deploymentsFactory ;
2125
2226 /**
2327 * @var ServiceShellUser
2428 */
25- private $ serviceShellUser ;
29+ private ServiceShellUser $ serviceShellUser ;
30+ /**
31+ * @var Config
32+ */
33+ private Config $ config ;
2634
2735 /**
2836 * Initialize dependencies.
2937 *
3038 * @param DeploymentsFactory $deploymentsFactory
3139 * @param ServiceShellUser $serviceShellUser
32- * @param ?string $name
40+ * @param Config $config
41+ * @param string|null $name
3342 */
3443 public function __construct (
3544 DeploymentsFactory $ deploymentsFactory ,
3645 ServiceShellUser $ serviceShellUser ,
37- $ name = null
46+ Config $ config ,
47+ ?string $ name = null
3848 ) {
3949 $ this ->deploymentsFactory = $ deploymentsFactory ;
4050 $ this ->serviceShellUser = $ serviceShellUser ;
51+ $ this ->config = $ config ;
4152 parent ::__construct ($ name );
4253 }
4354
@@ -47,11 +58,11 @@ public function __construct(
4758 protected function configure ()
4859 {
4960 $ this ->setName ("newrelic:create:deploy-marker " );
50- $ this ->setDescription ("Check the deploy queue for entries and create an appropriate deploy marker. " )
61+ $ this ->setDescription ("Create a deployment marker in New Relic (supports both v2 REST and NerdGraph) " )
5162 ->addArgument (
5263 'message ' ,
5364 InputArgument::REQUIRED ,
54- 'Deploy Message? '
65+ 'Deploy Message / Description '
5566 )
5667 ->addArgument (
5768 'change_log ' ,
@@ -65,24 +76,110 @@ protected function configure()
6576 )->addArgument (
6677 'revision ' ,
6778 InputArgument::OPTIONAL ,
68- 'Revision '
79+ 'Revision / Version '
80+ )
81+ ->addOption (
82+ 'commit ' ,
83+ 'c ' ,
84+ InputOption::VALUE_OPTIONAL ,
85+ 'Git commit hash for this deployment (NerdGraph only) '
86+ )
87+ ->addOption (
88+ 'deep-link ' ,
89+ 'd ' ,
90+ InputOption::VALUE_OPTIONAL ,
91+ 'Deep link to deployment details (NerdGraph only) '
92+ )
93+ ->addOption (
94+ 'group-id ' ,
95+ 'g ' ,
96+ InputOption::VALUE_OPTIONAL ,
97+ 'Group ID for organizing deployments (NerdGraph only) '
6998 );
7099 parent ::configure ();
71100 }
72101
73102 /**
74103 * @inheritdoc
75104 */
76- protected function execute (InputInterface $ input , OutputInterface $ output )
105+ protected function execute (InputInterface $ input , OutputInterface $ output ): int
106+ {
107+ $ isEnabled = $ this ->config ->isNewRelicEnabled ();
108+ if (!$ isEnabled ) {
109+ $ output ->writeln ('<error>✗ New Relic is not enabled. Please check your configuration.</error> ' );
110+ return Command::FAILURE ;
111+ }
112+ try {
113+ $ result = $ this ->deploymentsFactory ->create ()->setDeployment (
114+ $ input ->getArgument ('message ' ),
115+ $ input ->getArgument ('change_log ' ) ?: false ,
116+ $ this ->serviceShellUser ->get ($ input ->getArgument ('user ' )) ?: false ,
117+ $ input ->getArgument ('revision ' ),
118+ $ input ->getOption ('commit ' ),
119+ $ input ->getOption ('deep-link ' ),
120+ $ input ->getOption ('group-id ' )
121+ );
122+
123+ if ($ result !== false ) {
124+ $ output ->writeln ('<info>✓ NewRelic deployment marker created successfully!</info> ' );
125+
126+ // Display enhanced details if available (from NerdGraph)
127+ if (is_array ($ result ) && isset ($ result ['deploymentId ' ])) {
128+ $ this ->displayDeploymentDetails ($ output , $ result );
129+ }
130+
131+ return Command::SUCCESS ;
132+ } else {
133+ $ output ->writeln ('<error>✗ Failed to create deployment marker</error> ' );
134+ return Command::FAILURE ;
135+ }
136+ } catch (\Exception $ e ) {
137+ $ output ->writeln ('<error>✗ Error: ' . $ e ->getMessage () . '</error> ' );
138+ return Command::FAILURE ;
139+ }
140+ }
141+
142+ /**
143+ * Display deployment details from NerdGraph response
144+ *
145+ * @param OutputInterface $output
146+ * @param array $deployment
147+ */
148+ private function displayDeploymentDetails (OutputInterface $ output , array $ deployment ): void
77149 {
78- $ this ->deploymentsFactory ->create ()->setDeployment (
79- $ input ->getArgument ('message ' ),
80- $ input ->getArgument ('change_log ' ),
81- $ this ->serviceShellUser ->get ($ input ->getArgument ('user ' )),
82- $ input ->getArgument ('revision ' )
83- );
84- $ output ->writeln ('<info>NewRelic deployment information sent</info> ' );
150+ $ output ->writeln ('' );
151+ $ output ->writeln ('<comment>Deployment Details:</comment> ' );
152+
153+ $ table = new Table ($ output );
154+ $ table ->setHeaders (['Field ' , 'Value ' ]);
155+
156+ $ rows = [
157+ ['Deployment ID ' , $ deployment ['deploymentId ' ] ?? 'N/A ' ],
158+ ['Entity GUID ' , $ deployment ['entityGuid ' ] ?? 'N/A ' ],
159+ ['Version ' , $ deployment ['version ' ] ?? 'N/A ' ],
160+ ['Description ' , $ deployment ['description ' ] ?? 'N/A ' ],
161+ ['User ' , $ deployment ['user ' ] ?? 'N/A ' ],
162+ ['Timestamp ' , $ deployment ['timestamp ' ] ?
163+ date (
164+ 'Y-m-d H:i:s ' ,
165+ (int )($ deployment ['timestamp ' ] / 1000 )
166+ ) : 'N/A ' ]
167+ ];
168+
169+ if (!empty ($ deployment ['changelog ' ])) {
170+ $ rows [] = ['Change log ' , $ deployment ['changelog ' ]];
171+ }
172+ if (!empty ($ deployment ['commit ' ])) {
173+ $ rows [] = ['Commit ' , $ deployment ['commit ' ]];
174+ }
175+ if (!empty ($ deployment ['deepLink ' ])) {
176+ $ rows [] = ['Deep Link ' , $ deployment ['deepLink ' ]];
177+ }
178+ if (!empty ($ deployment ['groupId ' ])) {
179+ $ rows [] = ['Group ID ' , $ deployment ['groupId ' ]];
180+ }
85181
86- return 0 ;
182+ $ table ->setRows ($ rows );
183+ $ table ->render ();
87184 }
88185}
0 commit comments