| | |
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.extensions.PatchsetHook;
|
| | | import com.gitblit.manager.IGitblit;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.TicketModel;
|
| | |
| | | }
|
| | |
|
| | | if (isPatchsetRef(cmd.getRefName()) && processPatchsets) {
|
| | |
|
| | | if (ticketService == null) {
|
| | | sendRejection(cmd, "Sorry, the ticket service is unavailable and can not accept patchsets at this time.");
|
| | | continue;
|
| | |
| | | continue;
|
| | | }
|
| | |
|
| | | if (cmd.getNewId().equals(ObjectId.zeroId())) {
|
| | | // ref deletion request
|
| | | if (cmd.getRefName().startsWith(Constants.R_TICKET)) {
|
| | | if (user.canDeleteRef(repository)) {
|
| | | batch.addCommand(cmd);
|
| | | } else {
|
| | | sendRejection(cmd, "Sorry, you do not have permission to delete {}", cmd.getRefName());
|
| | | }
|
| | | } else {
|
| | | sendRejection(cmd, "Sorry, you can not delete {}", cmd.getRefName());
|
| | | }
|
| | | continue;
|
| | | }
|
| | |
|
| | | if (patchsetRefCmd != null) {
|
| | | sendRejection(cmd, "You may only push one patchset at a time.");
|
| | | continue;
|
| | | }
|
| | |
|
| | | LOGGER.info(MessageFormat.format("Verifying {0} push ref \"{1}\" received from {2}",
|
| | | repository.name, cmd.getRefName(), user.username));
|
| | |
|
| | | // responsible verification
|
| | | String responsible = PatchsetCommand.getSingleOption(cmd, PatchsetCommand.RESPONSIBLE);
|
| | |
| | | // watcher verification
|
| | | List<String> watchers = PatchsetCommand.getOptions(cmd, PatchsetCommand.WATCH);
|
| | | if (!ArrayUtils.isEmpty(watchers)) {
|
| | | boolean verified = true;
|
| | | for (String watcher : watchers) {
|
| | | UserModel user = gitblit.getUserModel(watcher);
|
| | | if (user == null) {
|
| | | // watcher does not exist
|
| | | sendRejection(cmd, "Sorry, \"{0}\" is not a valid username for the watch list!", watcher);
|
| | | continue;
|
| | | verified = false;
|
| | | break;
|
| | | }
|
| | | }
|
| | | if (!verified) {
|
| | | continue;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | patchsetRefCmd.setResult(Result.OK);
|
| | |
|
| | | // update the ticket branch ref
|
| | | RefUpdate ru = updateRef(patchsetCmd.getTicketBranch(), patchsetCmd.getNewId());
|
| | | RefUpdate ru = updateRef(
|
| | | patchsetCmd.getTicketBranch(),
|
| | | patchsetCmd.getNewId(),
|
| | | patchsetCmd.getPatchsetType());
|
| | | updateReflog(ru);
|
| | |
|
| | | TicketModel ticket = processPatchset(patchsetCmd);
|
| | |
| | | * @return the patchset command
|
| | | */
|
| | | private PatchsetCommand preparePatchset(ReceiveCommand cmd) {
|
| | | LOGGER.info(MessageFormat.format("Preparing {0} patchset command for \"{1}\" received from {2}",
|
| | | repository.name, cmd.getRefName(), user.username));
|
| | | String branch = getIntegrationBranch(cmd.getRefName());
|
| | | long number = getTicketId(cmd.getRefName());
|
| | |
|
| | |
| | | RefLogUtils.updateRefLog(user, getRepository(),
|
| | | Arrays.asList(new ReceiveCommand(cmd.getOldId(), cmd.getNewId(), cmd.getRefName())));
|
| | |
|
| | | // call any patchset hooks
|
| | | for (PatchsetHook hook : gitblit.getExtensions(PatchsetHook.class)) {
|
| | | try {
|
| | | hook.onNewPatchset(ticket);
|
| | | } catch (Exception e) {
|
| | | LOGGER.error("Failed to execute extension", e);
|
| | | }
|
| | | }
|
| | |
|
| | | return ticket;
|
| | | } else {
|
| | | sendError("FAILED to create ticket");
|
| | |
| | | // log the new patchset ref
|
| | | RefLogUtils.updateRefLog(user, getRepository(),
|
| | | Arrays.asList(new ReceiveCommand(cmd.getOldId(), cmd.getNewId(), cmd.getRefName())));
|
| | |
|
| | | // call any patchset hooks
|
| | | final boolean isNewPatchset = change.patchset.rev == 1;
|
| | | for (PatchsetHook hook : gitblit.getExtensions(PatchsetHook.class)) {
|
| | | try {
|
| | | if (isNewPatchset) {
|
| | | hook.onNewPatchset(ticket);
|
| | | } else {
|
| | | hook.onUpdatePatchset(ticket);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LOGGER.error("Failed to execute extension", e);
|
| | | }
|
| | | }
|
| | |
|
| | | // return the updated ticket
|
| | | return ticket;
|
| | |
| | | }
|
| | |
|
| | | TicketModel ticket = ticketService.getTicket(repository, ticketNumber);
|
| | | if (ticket == null) {
|
| | | continue;
|
| | | }
|
| | | String integrationBranch;
|
| | | if (StringUtils.isEmpty(ticket.mergeTo)) {
|
| | | // unspecified integration branch
|
| | |
| | | psCmd.updateTicket(c, mergeTo, ticket, null);
|
| | |
|
| | | // create a ticket patchset ref
|
| | | updateRef(psCmd.getPatchsetBranch(), c.getId());
|
| | | RefUpdate ru = updateRef(psCmd.getTicketBranch(), c.getId());
|
| | | updateRef(psCmd.getPatchsetBranch(), c.getId(), patchset.type);
|
| | | RefUpdate ru = updateRef(psCmd.getTicketBranch(), c.getId(), patchset.type);
|
| | | updateReflog(ru);
|
| | |
|
| | | // create a change from the patchset command
|
| | |
| | |
|
| | | if (parseMessage) {
|
| | | // parse commit message looking for fixes/closes #n
|
| | | Pattern p = Pattern.compile("(?:fixes|closes)[\\s-]+#?(\\d+)", Pattern.CASE_INSENSITIVE);
|
| | | Matcher m = p.matcher(commit.getFullMessage());
|
| | | while (m.find()) {
|
| | | String val = m.group();
|
| | | return Long.parseLong(val);
|
| | | String dx = "(?:fixes|closes)[\\s-]+#?(\\d+)";
|
| | | String x = settings.getString(Keys.tickets.closeOnPushCommitMessageRegex, dx);
|
| | | if (StringUtils.isEmpty(x)) {
|
| | | x = dx;
|
| | | }
|
| | | try {
|
| | | Pattern p = Pattern.compile(x, Pattern.CASE_INSENSITIVE);
|
| | | Matcher m = p.matcher(commit.getFullMessage());
|
| | | while (m.find()) {
|
| | | String val = m.group(1);
|
| | | return Long.parseLong(val);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LOGGER.error(String.format("Failed to parse \"%s\" in commit %s", x, commit.getName()), e);
|
| | | }
|
| | | }
|
| | | return 0L;
|
| | |
| | | return newPatchset;
|
| | | }
|
| | |
|
| | | private RefUpdate updateRef(String ref, ObjectId newId) {
|
| | | private RefUpdate updateRef(String ref, ObjectId newId, PatchsetType type) {
|
| | | ObjectId ticketRefId = ObjectId.zeroId();
|
| | | try {
|
| | | ticketRefId = getRepository().resolve(ref);
|
| | |
| | | try {
|
| | | RefUpdate ru = getRepository().updateRef(ref, false);
|
| | | ru.setRefLogIdent(getRefLogIdent());
|
| | | ru.setForceUpdate(true);
|
| | | switch (type) {
|
| | | case Amend:
|
| | | case Rebase:
|
| | | case Rebase_Squash:
|
| | | case Squash:
|
| | | ru.setForceUpdate(true);
|
| | | break;
|
| | | default:
|
| | | break;
|
| | | }
|
| | |
|
| | | ru.setExpectedOldObjectId(ticketRefId);
|
| | | ru.setNewObjectId(newId);
|
| | | RefUpdate.Result result = ru.update(getRevWalk());
|
| | |
| | | ObjectId.fromString(mergeResult.sha), oldRef.getName());
|
| | | RefLogUtils.updateRefLog(user, getRepository(), Arrays.asList(cmd));
|
| | | }
|
| | |
|
| | | // call patchset hooks
|
| | | for (PatchsetHook hook : gitblit.getExtensions(PatchsetHook.class)) {
|
| | | try {
|
| | | hook.onMergePatchset(ticket);
|
| | | } catch (Exception e) {
|
| | | LOGGER.error("Failed to execute extension", e);
|
| | | }
|
| | | }
|
| | | return mergeResult.status;
|
| | | } else {
|
| | | LOGGER.error("FAILED to resolve ticket {} by merge from web ui", ticketId);
|