Search in sources :

Example 21 with Repository

use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.

the class RawFilter method extractRepositoryName.

/**
	 * Extract the repository name from the url.
	 *
	 * @param url
	 * @return repository name
	 */
@Override
protected String extractRepositoryName(String url) {
    // get the repository name from the url by finding a known url suffix
    String repository = "";
    Repository r = null;
    int offset = 0;
    while (r == null) {
        int slash = url.indexOf('/', offset);
        if (slash == -1) {
            repository = url;
        } else {
            repository = url.substring(0, slash);
        }
        r = repositoryManager.getRepository(repository, false);
        if (r == null) {
            // try again
            offset = slash + 1;
        } else {
            // close the repo
            r.close();
        }
        if (repository.equals(url)) {
            // either only repository in url or no repository found
            break;
        }
    }
    return repository;
}
Also used : Repository(org.eclipse.jgit.lib.Repository)

Example 22 with Repository

use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.

the class ITicketService method renameMilestone.

/**
	 * Renames a milestone.
	 *
	 * @param repository
	 * @param oldName
	 * @param newName
	 * @param createdBy
	 * @param notifyOpenTickets
	 * @return true if successful
	 * @since 1.6.0
	 */
public synchronized boolean renameMilestone(RepositoryModel repository, String oldName, String newName, String createdBy, boolean notifyOpenTickets) {
    if (StringUtils.isEmpty(newName)) {
        throw new IllegalArgumentException("new milestone can not be empty!");
    }
    Repository db = null;
    try {
        db = repositoryManager.getRepository(repository.name);
        TicketMilestone tm = getMilestone(repository, oldName);
        if (tm == null) {
            return false;
        }
        StoredConfig config = db.getConfig();
        config.unsetSection(MILESTONE, oldName);
        config.setString(MILESTONE, newName, STATUS, tm.status.name());
        config.setString(MILESTONE, newName, COLOR, tm.color);
        if (tm.due != null) {
            config.setString(MILESTONE, newName, DUE, new SimpleDateFormat(DUE_DATE_PATTERN).format(tm.due));
        }
        config.save();
        milestonesCache.remove(repository.name);
        TicketNotifier notifier = createNotifier();
        for (QueryResult qr : tm.tickets) {
            Change change = new Change(createdBy);
            change.setField(Field.milestone, newName);
            TicketModel ticket = updateTicket(repository, qr.number, change);
            if (notifyOpenTickets && ticket.isOpen()) {
                notifier.queueMailing(ticket);
            }
        }
        if (notifyOpenTickets) {
            notifier.sendAll();
        }
        return true;
    } catch (IOException e) {
        log.error("failed to rename milestone " + oldName + " in " + repository, e);
    } finally {
        if (db != null) {
            db.close();
        }
    }
    return false;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 23 with Repository

use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.

the class ITicketService method updateMilestone.

/**
	 * Updates a milestone.
	 *
	 * @param repository
	 * @param milestone
	 * @param createdBy
	 * @return true if successful
	 * @since 1.4.0
	 */
public synchronized boolean updateMilestone(RepositoryModel repository, TicketMilestone milestone, String createdBy) {
    Repository db = null;
    try {
        db = repositoryManager.getRepository(repository.name);
        StoredConfig config = db.getConfig();
        config.setString(MILESTONE, milestone.name, STATUS, milestone.status.name());
        config.setString(MILESTONE, milestone.name, COLOR, milestone.color);
        if (milestone.due != null) {
            config.setString(MILESTONE, milestone.name, DUE, new SimpleDateFormat(DUE_DATE_PATTERN).format(milestone.due));
        }
        config.save();
        milestonesCache.remove(repository.name);
        return true;
    } catch (IOException e) {
        log.error("failed to update milestone " + milestone + " in " + repository, e);
    } finally {
        if (db != null) {
            db.close();
        }
    }
    return false;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 24 with Repository

use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.

the class ITicketService method renameLabel.

/**
	 * Renames a label.
	 *
	 * @param repository
	 * @param oldName
	 * @param newName
	 * @param createdBy
	 * @return true if the rename was successful
	 * @since 1.4.0
	 */
public synchronized boolean renameLabel(RepositoryModel repository, String oldName, String newName, String createdBy) {
    if (StringUtils.isEmpty(newName)) {
        throw new IllegalArgumentException("new label can not be empty!");
    }
    Repository db = null;
    try {
        db = repositoryManager.getRepository(repository.name);
        TicketLabel label = getLabel(repository, oldName);
        StoredConfig config = db.getConfig();
        config.unsetSection(LABEL, oldName);
        config.setString(LABEL, newName, COLOR, label.color);
        config.save();
        for (QueryResult qr : label.tickets) {
            Change change = new Change(createdBy);
            change.unlabel(oldName);
            change.label(newName);
            updateTicket(repository, qr.number, change);
        }
        return true;
    } catch (IOException e) {
        log.error("failed to rename label " + oldName + " in " + repository, e);
    } finally {
        if (db != null) {
            db.close();
        }
    }
    return false;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) Change(com.gitblit.models.TicketModel.Change) IOException(java.io.IOException)

Example 25 with Repository

use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.

the class ITicketService method getMilestones.

/**
	 * Returns the list of milestones for the repository.
	 *
	 * @param repository
	 * @return the list of milestones
	 * @since 1.4.0
	 */
public List<TicketMilestone> getMilestones(RepositoryModel repository) {
    String key = repository.name;
    if (milestonesCache.containsKey(key)) {
        return milestonesCache.get(key);
    }
    List<TicketMilestone> list = new ArrayList<TicketMilestone>();
    Repository db = repositoryManager.getRepository(repository.name);
    try {
        StoredConfig config = db.getConfig();
        Set<String> names = config.getSubsections(MILESTONE);
        for (String name : names) {
            TicketMilestone milestone = new TicketMilestone(name);
            milestone.status = Status.fromObject(config.getString(MILESTONE, name, STATUS), milestone.status);
            milestone.color = config.getString(MILESTONE, name, COLOR);
            String due = config.getString(MILESTONE, name, DUE);
            if (!StringUtils.isEmpty(due)) {
                try {
                    milestone.due = new SimpleDateFormat(DUE_DATE_PATTERN).parse(due);
                } catch (ParseException e) {
                    log.error("failed to parse {} milestone {} due date \"{}\"", new Object[] { repository, name, due });
                }
            }
            list.add(milestone);
        }
        milestonesCache.put(key, Collections.unmodifiableList(list));
    } catch (Exception e) {
        log.error("invalid tickets settings for " + repository, e);
    } finally {
        db.close();
    }
    return list;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) ParseException(java.text.ParseException) IOException(java.io.IOException)

Aggregations

Repository (org.eclipse.jgit.lib.Repository)326 IOException (java.io.IOException)103 RevWalk (org.eclipse.jgit.revwalk.RevWalk)102 Test (org.junit.Test)81 RevCommit (org.eclipse.jgit.revwalk.RevCommit)76 ObjectId (org.eclipse.jgit.lib.ObjectId)72 File (java.io.File)43 TestRepository (org.eclipse.jgit.junit.TestRepository)40 Change (com.google.gerrit.reviewdb.client.Change)39 OrmException (com.google.gwtorm.server.OrmException)39 Ref (org.eclipse.jgit.lib.Ref)35 Project (com.google.gerrit.reviewdb.client.Project)32 ArrayList (java.util.ArrayList)31 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)27 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)26 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)24 Map (java.util.Map)23 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)23 RepositoryModel (com.gitblit.models.RepositoryModel)20 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)20