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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations