InlineEdit: Add REST endpoint to retrieve commit message
Change-Id: I9017df268614e8035513af173a7067a8aa10fcec
This commit is contained in:
		
				
					committed by
					
						
						David Pursehouse
					
				
			
			
				
	
			
			
			
						parent
						
							c967e151a7
						
					
				
				
					commit
					3d2c070206
				
			@@ -1369,6 +1369,30 @@ specified file was deleted in the change edit "`204 No Content`" is returned.
 | 
				
			|||||||
  RnJvbSA3ZGFkY2MxNTNmZGVhMTdhYTg0ZmYzMmE2ZTI0NWRiYjY...
 | 
					  RnJvbSA3ZGFkY2MxNTNmZGVhMTdhYTg0ZmYzMmE2ZTI0NWRiYjY...
 | 
				
			||||||
----
 | 
					----
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[get-edit-message]]
 | 
				
			||||||
 | 
					=== Retrieve commit message from Change Edit or current patch set of the change
 | 
				
			||||||
 | 
					--
 | 
				
			||||||
 | 
					'GET /changes/link:#change-id[\{change-id\}]/edit:message
 | 
				
			||||||
 | 
					--
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Retrieves commit message from change edit or from current patch set when
 | 
				
			||||||
 | 
					change edit doesn't exist.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.Request
 | 
				
			||||||
 | 
					----
 | 
				
			||||||
 | 
					  GET /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/edit:message HTTP/1.0
 | 
				
			||||||
 | 
					----
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The commit message is returned as base64 encoded string.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.Response
 | 
				
			||||||
 | 
					----
 | 
				
			||||||
 | 
					  HTTP/1.1 200 OK
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  VGhpcyBpcyBhIGNvbW1pdCBtZXNzYWdlCgpDaGFuZ2UtSWQ6IElhYzhmZGM1MGRlZjFiYWUzYjAz
 | 
				
			||||||
 | 
					M2JhNjcxZTk0OTBmNzUxNDU5ZGUzCg==
 | 
				
			||||||
 | 
					----
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[publish-edit]]
 | 
					[[publish-edit]]
 | 
				
			||||||
=== Publish Change Edit
 | 
					=== Publish Change Edit
 | 
				
			||||||
--
 | 
					--
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -450,6 +450,36 @@ public class ChangeUtil {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public String getMessage(Change change)
 | 
				
			||||||
 | 
					      throws NoSuchChangeException, OrmException,
 | 
				
			||||||
 | 
					      MissingObjectException, IncorrectObjectTypeException, IOException {
 | 
				
			||||||
 | 
					    Change.Id changeId = change.getId();
 | 
				
			||||||
 | 
					    PatchSet ps = db.get().patchSets().get(change.currentPatchSetId());
 | 
				
			||||||
 | 
					    if (ps == null) {
 | 
				
			||||||
 | 
					      throw new NoSuchChangeException(changeId);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Repository git;
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      git = gitManager.openRepository(change.getProject());
 | 
				
			||||||
 | 
					    } catch (RepositoryNotFoundException e) {
 | 
				
			||||||
 | 
					      throw new NoSuchChangeException(changeId, e);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      RevWalk revWalk = new RevWalk(git);
 | 
				
			||||||
 | 
					      try {
 | 
				
			||||||
 | 
					        RevCommit commit =
 | 
				
			||||||
 | 
					            revWalk.parseCommit(ObjectId.fromString(ps.getRevision()
 | 
				
			||||||
 | 
					                .get()));
 | 
				
			||||||
 | 
					        return commit.getFullMessage();
 | 
				
			||||||
 | 
					      } finally {
 | 
				
			||||||
 | 
					        revWalk.release();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } finally {
 | 
				
			||||||
 | 
					      git.close();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public void deleteDraftChange(Change change)
 | 
					  public void deleteDraftChange(Change change)
 | 
				
			||||||
      throws NoSuchChangeException, OrmException, IOException {
 | 
					      throws NoSuchChangeException, OrmException, IOException {
 | 
				
			||||||
    Change.Id changeId = change.getId();
 | 
					    Change.Id changeId = change.getId();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,6 +24,7 @@ import com.google.gerrit.extensions.restapi.AcceptsDelete;
 | 
				
			|||||||
import com.google.gerrit.extensions.restapi.AcceptsPost;
 | 
					import com.google.gerrit.extensions.restapi.AcceptsPost;
 | 
				
			||||||
import com.google.gerrit.extensions.restapi.AuthException;
 | 
					import com.google.gerrit.extensions.restapi.AuthException;
 | 
				
			||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
 | 
					import com.google.gerrit.extensions.restapi.BadRequestException;
 | 
				
			||||||
 | 
					import com.google.gerrit.extensions.restapi.BinaryResult;
 | 
				
			||||||
import com.google.gerrit.extensions.restapi.ChildCollection;
 | 
					import com.google.gerrit.extensions.restapi.ChildCollection;
 | 
				
			||||||
import com.google.gerrit.extensions.restapi.DefaultInput;
 | 
					import com.google.gerrit.extensions.restapi.DefaultInput;
 | 
				
			||||||
import com.google.gerrit.extensions.restapi.IdString;
 | 
					import com.google.gerrit.extensions.restapi.IdString;
 | 
				
			||||||
@@ -38,12 +39,14 @@ import com.google.gerrit.extensions.restapi.RestView;
 | 
				
			|||||||
import com.google.gerrit.reviewdb.client.Change;
 | 
					import com.google.gerrit.reviewdb.client.Change;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.PatchSet;
 | 
					import com.google.gerrit.reviewdb.client.PatchSet;
 | 
				
			||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
 | 
					import com.google.gerrit.reviewdb.server.ReviewDb;
 | 
				
			||||||
 | 
					import com.google.gerrit.server.ChangeUtil;
 | 
				
			||||||
import com.google.gerrit.server.edit.ChangeEdit;
 | 
					import com.google.gerrit.server.edit.ChangeEdit;
 | 
				
			||||||
import com.google.gerrit.server.edit.ChangeEditJson;
 | 
					import com.google.gerrit.server.edit.ChangeEditJson;
 | 
				
			||||||
import com.google.gerrit.server.edit.ChangeEditModifier;
 | 
					import com.google.gerrit.server.edit.ChangeEditModifier;
 | 
				
			||||||
import com.google.gerrit.server.edit.ChangeEditUtil;
 | 
					import com.google.gerrit.server.edit.ChangeEditUtil;
 | 
				
			||||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
 | 
					import com.google.gerrit.server.patch.PatchListNotAvailableException;
 | 
				
			||||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
 | 
					import com.google.gerrit.server.project.InvalidChangeOperationException;
 | 
				
			||||||
 | 
					import com.google.gerrit.server.project.NoSuchChangeException;
 | 
				
			||||||
import com.google.gwtorm.server.OrmException;
 | 
					import com.google.gwtorm.server.OrmException;
 | 
				
			||||||
import com.google.inject.Inject;
 | 
					import com.google.inject.Inject;
 | 
				
			||||||
import com.google.inject.Provider;
 | 
					import com.google.inject.Provider;
 | 
				
			||||||
@@ -475,4 +478,31 @@ public class ChangeEdits implements
 | 
				
			|||||||
      return Response.none();
 | 
					      return Response.none();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Singleton
 | 
				
			||||||
 | 
					  public static class GetMessage implements RestReadView<ChangeResource> {
 | 
				
			||||||
 | 
					    private final ChangeUtil changeUtil;
 | 
				
			||||||
 | 
					    private final ChangeEditUtil editUtil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Inject
 | 
				
			||||||
 | 
					    GetMessage(ChangeUtil changeUtil,
 | 
				
			||||||
 | 
					        ChangeEditUtil editUtil) {
 | 
				
			||||||
 | 
					      this.changeUtil = changeUtil;
 | 
				
			||||||
 | 
					      this.editUtil = editUtil;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public BinaryResult apply(ChangeResource rsrc) throws AuthException, IOException,
 | 
				
			||||||
 | 
					       OrmException, NoSuchChangeException {
 | 
				
			||||||
 | 
					      Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getChange());
 | 
				
			||||||
 | 
					      // TODO(davido): Clean this up by returning 404 when edit doesn't exist.
 | 
				
			||||||
 | 
					      // Client should call GET /changes/{id}/revisions/current/commit in this
 | 
				
			||||||
 | 
					      // case; or, to be consistent with GET content logic, the client could
 | 
				
			||||||
 | 
					      // call directly the right endpoint.
 | 
				
			||||||
 | 
					      String m = edit.isPresent()
 | 
				
			||||||
 | 
					        ? edit.get().getEditCommit().getFullMessage()
 | 
				
			||||||
 | 
					        : changeUtil.getMessage(rsrc.getChange());
 | 
				
			||||||
 | 
					      return BinaryResult.create(m).base64();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -109,6 +109,7 @@ public class Module extends RestApiModule {
 | 
				
			|||||||
    child(CHANGE_KIND, "edit:publish").to(PublishChangeEdit.class);
 | 
					    child(CHANGE_KIND, "edit:publish").to(PublishChangeEdit.class);
 | 
				
			||||||
    child(CHANGE_KIND, "edit:rebase").to(RebaseChangeEdit.class);
 | 
					    child(CHANGE_KIND, "edit:rebase").to(RebaseChangeEdit.class);
 | 
				
			||||||
    put(CHANGE_KIND, "edit:message").to(ChangeEdits.EditMessage.class);
 | 
					    put(CHANGE_KIND, "edit:message").to(ChangeEdits.EditMessage.class);
 | 
				
			||||||
 | 
					    get(CHANGE_KIND, "edit:message").to(ChangeEdits.GetMessage.class);
 | 
				
			||||||
    put(CHANGE_EDIT_KIND, "/").to(ChangeEdits.Put.class);
 | 
					    put(CHANGE_EDIT_KIND, "/").to(ChangeEdits.Put.class);
 | 
				
			||||||
    delete(CHANGE_EDIT_KIND).to(ChangeEdits.DeleteContent.class);
 | 
					    delete(CHANGE_EDIT_KIND).to(ChangeEdits.DeleteContent.class);
 | 
				
			||||||
    get(CHANGE_EDIT_KIND, "/").to(ChangeEdits.Get.class);
 | 
					    get(CHANGE_EDIT_KIND, "/").to(ChangeEdits.Get.class);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user