use of org.eclipse.jgit.lib.StoredConfig 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.StoredConfig 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.StoredConfig 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;
}
use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.
the class JGitUtils method repairFetchSpecs.
/**
* Automatic repair of (some) invalid refspecs. These are the result of a
* bug in JGit cloning where a double forward-slash was injected. :(
*
* @param repository
* @return true, if the refspecs were repaired
*/
public static boolean repairFetchSpecs(Repository repository) {
StoredConfig rc = repository.getConfig();
// auto-repair broken fetch ref specs
for (String name : rc.getSubsections("remote")) {
int invalidSpecs = 0;
int repairedSpecs = 0;
List<String> specs = new ArrayList<String>();
for (String spec : rc.getStringList("remote", name, "fetch")) {
try {
RefSpec rs = new RefSpec(spec);
// valid spec
specs.add(spec);
} catch (IllegalArgumentException e) {
// invalid spec
invalidSpecs++;
if (spec.contains("//")) {
// auto-repair this known spec bug
spec = spec.replace("//", "/");
specs.add(spec);
repairedSpecs++;
}
}
}
if (invalidSpecs == repairedSpecs && repairedSpecs > 0) {
// the fetch specs were automatically repaired
rc.setStringList("remote", name, "fetch", specs);
try {
rc.save();
rc.load();
LOGGER.debug("repaired {} invalid fetch refspecs for {}", repairedSpecs, repository.getDirectory());
return true;
} catch (Exception e) {
LOGGER.error(null, e);
}
} else if (invalidSpecs > 0) {
LOGGER.error("mirror executor found {} invalid fetch refspecs for {}", invalidSpecs, repository.getDirectory());
}
}
return false;
}
use of org.eclipse.jgit.lib.StoredConfig in project che by eclipse.
the class JGitConnection method remoteList.
@Override
public List<Remote> remoteList(String remoteName, boolean verbose) throws GitException {
StoredConfig config = repository.getConfig();
Set<String> remoteNames = new HashSet<>(config.getSubsections(ConfigConstants.CONFIG_KEY_REMOTE));
if (remoteName != null && remoteNames.contains(remoteName)) {
remoteNames.clear();
remoteNames.add(remoteName);
}
List<Remote> result = new ArrayList<>(remoteNames.size());
for (String remote : remoteNames) {
try {
List<URIish> uris = new RemoteConfig(config, remote).getURIs();
result.add(newDto(Remote.class).withName(remote).withUrl(uris.isEmpty() ? null : uris.get(0).toString()));
} catch (URISyntaxException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
return result;
}
Aggregations