| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This dispatcher takes care of updating and returning information about this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * projects git repository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | class DeployDispatcher extends Dispatcher { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 	const ACTION_DEPLOY = 'deploys'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	 * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	private static $action_types = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 		self::ACTION_DEPLOY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	 * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	public static $allowed_actions = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		'history', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		'currentbuild', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		'deployment', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		'log', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		'start' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 * @var \DNProject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	protected $project = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	 * @var \DNEnvironment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	protected $environment = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 39 |  | View Code Duplication | 	public function init() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		parent::init(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		$this->project = $this->getCurrentProject(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		if (!$this->project) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 			return $this->project404Response(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		// Performs canView permission check by limiting visible projects | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		$this->environment = $this->getCurrentEnvironment($this->project); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		if (!$this->environment) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			return $this->environment404Response(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	 * @param \SS_HTTPRequest $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	 * @return \HTMLText|\SS_HTTPResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	public function index(\SS_HTTPRequest $request) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		return $this->redirect(\Controller::join_links($this->Link(), 'history'), 302); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * @param \SS_HTTPRequest $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	 * @return \SS_HTTPResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	public function history(SS_HTTPRequest $request) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		$data = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		$list = $this->DeployHistory(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		$page = $request->getVar('page') ?: 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		if ($page > $list->TotalPages()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 			$page = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		if ($page < 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 			$page = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		$start = ($page - 1) * $list->getPageLength(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		$list->setPageStart((int) $start); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		if (empty($list)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			return $this->getAPIResponse(['list' => []], 200); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		foreach ($list as $deployment) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 			$data[] = $this->getDeploymentData($deployment); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 		return $this->getAPIResponse([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 			'list' => $data, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 			'pagelength' => $list->getPageLength(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			'totalpages' => $list->TotalPages(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 			'currentpage' => $list->CurrentPage() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		], 200); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	 * @param \SS_HTTPRequest $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	 * @return \SS_HTTPResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	public function currentbuild(SS_HTTPRequest $request) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 		$currentBuild = $this->environment->CurrentBuild(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 		if (!$currentBuild) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 			return $this->getAPIResponse(['deployment' => []], 200); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		return $this->getAPIResponse(['deployment' => $this->getDeploymentData($currentBuild)], 200); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	 * @param \SS_HTTPRequest $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	 * @return \SS_HTTPResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	public function deployment(SS_HTTPRequest $request) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 		$deployment = DNDeployment::get()->byId($request->param('ID')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 		if (!$deployment || !$deployment->exists()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 			return $this->getAPIResponse(['message' => 'This deployment does not exist'], 404); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 		if (!$deployment->canView()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 			return $this->getAPIResponse(['message' => 'You are not authorized to deploy this environment'], 403); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		return $this->getAPIResponse(['deployment' => $this->getDeploymentData($deployment)], 200); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	 * @param \SS_HTTPRequest $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 	 * @return \SS_HTTPResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	public function log(SS_HTTPRequest $request) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 		$deployment = DNDeployment::get()->byId($request->params('ID')); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 		if (!$deployment || !$deployment->exists) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 			return $this->getAPIResponse(['message' => 'This deployment does not exist'], 404); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 		if(!$deployment->canView()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 			return $this->getAPIResponse(['message' => 'You are not authorized to view this environment'], 403); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 		$log = $deployment->log(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 		$content = $log->exists() ? $log->content() : 'Waiting for action to start'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 		$lines = explode(PHP_EOL, $content); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 		return $this->getAPIResponse(['message' => $lines, 'status' => $deployment->Status], 200); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 	 * @param \SS_HTTPRequest $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 	 * @return \SS_HTTPResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 	public function start(SS_HTTPRequest $request) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 		$this->checkSecurityToken(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 		if (!$this->environment->canDeploy(Member::currentUser())) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 			return $this->getAPIResponse(['message' => 'You are not authorized to deploy this environment'], 403); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 		// @todo the strategy should have been saved when there has been a request for an | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 		// approval or a bypass. This saved state needs to be checked if it's invalidated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 		// if another deploy happens before this one | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 		$options = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 			'sha' => $request->requestVar('sha'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 		$strategy = $this->environment->Backend()->planDeploy($this->environment, $options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 		$strategy->fromArray($request->requestVars()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 		$deployment = $strategy->createDeployment(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 		$deployment->Summary = null; // todo add this | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 		$deployment->DatePlanned = null; // todo add this | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 		// Skip through the approval state for now. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 		$deployment->getMachine()->apply(DNDeployment::TR_SUBMIT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 		$deployment->getMachine()->apply(DNDeployment::TR_QUEUE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 		$location = \Controller::join_links(Director::absoluteBaseURL(), $this->Link('log'), $deployment->ID); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 		$response = $this->getAPIResponse([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 			'message' => 'deployment has been queued', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 			'ID' => $deployment->ID, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 			'location' => $location | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  | 		], 201); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 		$response->addHeader('Location', $location); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 		return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 	 * @param string $action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 	public function Link($action = '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 		return \Controller::join_links($this->environment->Link(), self::ACTION_DEPLOY, $action); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 	 * @param string $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 	 * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 	public function getModel($name = '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  | 		return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | 	 * Return data about a single deployment. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 	 * @param DNDeployment $deployment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  | 	 * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 201 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 202 |  |  | 	protected function getDeploymentData(DNDeployment $deployment) { | 
            
                                                                        
                            
            
                                    
            
            
                | 203 |  |  | 		$currentBuild = $this->environment->CurrentBuild(); | 
            
                                                                        
                            
            
                                    
            
            
                | 204 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 205 |  |  | 		return [ | 
            
                                                                        
                            
            
                                    
            
            
                | 206 |  |  | 			'ID' => $deployment->ID, | 
            
                                                                        
                            
            
                                    
            
            
                | 207 |  |  | 			'CreatedDate' => $deployment->Created, | 
            
                                                                        
                            
            
                                    
            
            
                | 208 |  |  | 			'DatePlanned' => $deployment->DatePlanned, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 209 |  |  | 			'Summary' => $deployment->Summary, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 210 |  |  | 			'Branch' => $deployment->Branch, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 211 |  |  | 			'Tags' => $deployment->getTags()->toArray(), | 
            
                                                                        
                            
            
                                    
            
            
                | 212 |  |  | 			'Changes' => $deployment->getDeploymentStrategy()->getChanges(), | 
            
                                                                        
                            
            
                                    
            
            
                | 213 |  |  | 			'SHA' => $deployment->SHA, | 
            
                                                                        
                            
            
                                    
            
            
                | 214 |  |  | 			'CommitMessage' => $deployment->getCommitMessage(), | 
            
                                                                        
                            
            
                                    
            
            
                | 215 |  |  | 			'CommitURL' => $deployment->getCommitURL(), | 
            
                                                                        
                            
            
                                    
            
            
                | 216 |  |  | 			'Deployer' => $deployment->Deployer()->getName(), | 
            
                                                                        
                            
            
                                    
            
            
                | 217 |  |  | 			'Approver' => $deployment->Approver()->getName(), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 218 |  |  | 			'State' => $deployment->State, | 
            
                                                                        
                            
            
                                    
            
            
                | 219 |  |  | 			'IsCurrentBuild' => $currentBuild ? ($deployment->ID === $currentBuild->ID) : null | 
            
                                                                        
                            
            
                                    
            
            
                | 220 |  |  | 		]; | 
            
                                                                        
                            
            
                                    
            
            
                | 221 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 223 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 224 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.