public VersionInputBuilder(String projectKey, Version version) { this(projectKey); this.name = version.getName(); this.description = version.getDescription(); this.archived = version.isArchived(); this.released = version.isReleased(); this.releaseDate = version.getReleaseDate(); }
/** * Release a given version. * * @param projectKey The Project Key * @param versionName The name of the version */ protected void releaseVersion(String projectKey, String versionName, JiraSession session) { if (session == null) { LOGGER.warning("JIRA session could not be established"); return; } List<Version> versions = session.getVersions(projectKey); java.util.Optional<Version> matchingVersion = versions.stream() .filter(version -> version.getName().equals(versionName)) .findFirst(); if (matchingVersion.isPresent()) { Version version = matchingVersion.get(); Version releaseVersion = new Version(version.getSelf(), version.getId(), version.getName(), version.getDescription(), version.isArchived(), true, new DateTime()); session.releaseVersion(projectKey, releaseVersion); } }
private boolean match(Version version) { // Match regex if it exists if (pattern != null) { if (!pattern.matcher(version.getName()).matches()) return false; } // Filter released versions if (!showReleased && version.isReleased()) return false; // Filter archived versions if (!showArchived && version.isArchived()) return false; return true; }
@Override protected void doExecute(JiraRestClient jiraRestClient) throws Exception { final String theProjectKey = Strings.isNullOrEmpty(projectKey) ? getConfig().getProjectKey() : projectKey; final Iterable<Version> versions = jiraRestClient.getProjectClient().getProject(theProjectKey).get().getVersions(); if (!versions.iterator().hasNext()) { System.out.println("No versions found for project '" + theProjectKey + "'."); return; } System.out.println(String.format(DEFAULT_ROW_FORMAT, "Id", "Name", "Description")); for (Version eachVersion : versions) { System.out.println( String.format( DEFAULT_ROW_FORMAT, eachVersion.getId(), eachVersion.getName(), eachVersion.getDescription() == null ? "" : removeNewLines(eachVersion.getDescription()))); } } }
@Override public boolean isCPReleased(String cpVersion) { // For Jira, only accept GA version format x.y.z.GA, e.g. 7.1.2.GA // ignore CR version like 7.0.7.CR3 Matcher matcher = JIRAFIXVERSION.matcher(cpVersion); if (!matcher.matches()) { return false; } Promise<Project> promise = restClient.getProjectClient().getProject("JBEAP"); Project project = promise.claim(); Optional<Version> version = StreamSupport.stream(project.getVersions().spliterator(), false) .filter(v -> v.getName().equals(cpVersion)) .findAny(); if (version.isPresent()) { return version.get().isReleased(); } return false; } }
/** * Release given version in given project * @param projectKey * @param version */ public void releaseVersion(String projectKey, Version version) { LOGGER.fine("Releasing version: " + version.getName()); service.releaseVersion(projectKey, version); }
private Set<String> getVersionsByIds(com.atlassian.jira.rest.client.api.domain.Project jiraProject) { Set<String> versionsIds = new HashSet<>(); for (com.atlassian.jira.rest.client.api.domain.Version version : jiraProject.getVersions()) { versionsIds.add(String.valueOf(version.getId())); } return versionsIds; }
public List<Version> getVersions(String projectKey) { final URIBuilder builder = new URIBuilder(uri) .setPath(String.format("%s/project/%s/versions", baseApiPath, projectKey)); List<Map<String, Object>> decoded = Collections.emptyList(); try { URI uri = builder.build(); final Content content = buildGetRequest(uri) .execute() .returnContent(); decoded = objectMapper.readValue(content.asString(), new TypeReference<List<Map<String, Object>>>() { }); } catch (Exception e) { LOGGER.log(WARNING, "jira rest client get versions error. cause: " + e.getMessage(), e); } return decoded.stream().map( decodedVersion -> { final DateTime releaseDate = decodedVersion.containsKey("releaseDate") ? DATE_TIME_FORMATTER.parseDateTime((String) decodedVersion.get("releaseDate")) : null; return new Version(URI.create((String) decodedVersion.get("self")), Long.parseLong((String) decodedVersion.get("id")), (String) decodedVersion.get("name"), (String) decodedVersion.get("description"), (Boolean) decodedVersion.get("archived"), (Boolean) decodedVersion.get("released"), releaseDate); } ).collect( Collectors.toList() ); }
@Override protected void doExecute(JiraRestClient jiraRestClient) throws Exception { final String theProjectKey = Strings.isNullOrEmpty(projectKey) ? getConfig().getProjectKey() : projectKey; final Iterable<Version> versions = jiraRestClient.getProjectClient().getProject(theProjectKey).get().getVersions(); if (!versions.iterator().hasNext()) { System.out.println("No versions found for project '" + theProjectKey + "'."); return; } System.out.println(String.format(DEFAULT_ROW_FORMAT, "Id", "Name", "Description")); for (Version eachVersion : versions) { System.out.println( String.format( DEFAULT_ROW_FORMAT, eachVersion.getId(), eachVersion.getName(), eachVersion.getDescription() == null ? "" : removeNewLines(eachVersion.getDescription()))); } } }
JiraSite site = getSiteForProject(project); Optional<Version> sameNamedVersion = site.getVersions(realProjectKey).stream() .filter(version -> version.getName().equals(finalRealVersion) && version.isReleased()).findFirst();
/** * Get a version by its name * * @param projectKey The key for the project * @param name The version name * @return A RemoteVersion, or null if not found */ public Version getVersionByName(String projectKey, String name) { LOGGER.fine("Fetching versions from project: " + projectKey); List<Version> versions = getVersions(projectKey); if (versions == null) { return null; } for (Version version : versions) { if (version.getName().equals(name)) { return version; } } return null; }
public Version createVersion(String projectId, com.atlassian.jira.rest.client.api.domain.Version jiraVersion) { Objects.requireNonNull(jiraVersion, "Jira User cannot be null."); Version version = new Version(); version.setId(String.valueOf(jiraVersion.getId())); version.setProjectId(projectId); version.setName(jiraVersion.getName()); return version; } }
private Set<String> getVersions(com.atlassian.jira.rest.client.api.domain.Issue jiraIssue) { Set<String> versions = new HashSet<>(); for (Version version : jiraIssue.getAffectedVersions()) { versions.add(String.valueOf(version.getId())); } return versions; }
@Override public Version parse(JSONObject json) throws JSONException { final URI self = JsonParseUtil.getSelfUri(json); final Long id = JsonParseUtil.getOptionalLong(json, "id"); final String name = json.getString("name"); final String description = JsonParseUtil.getOptionalString(json, "description"); final boolean isArchived = json.getBoolean("archived"); final boolean isReleased = json.getBoolean("released"); final String releaseDateStr = JsonParseUtil.getOptionalString(json, "releaseDate"); final DateTime releaseDate = parseReleaseDate(releaseDateStr); return new Version(self, id, name, description, isArchived, isReleased, releaseDate); }
public VersionInputBuilder(String projectKey, Version version) { this(projectKey); this.name = version.getName(); this.description = version.getDescription(); this.archived = version.isArchived(); this.released = version.isReleased(); this.releaseDate = version.getReleaseDate(); }
JiraSite site = getSiteForProject(project); Optional<Version> sameNamedVersion = site.getVersions(realProjectKey).stream() .filter(version -> version.getName().equals(finalRealRelease) && version.isReleased()).findFirst();
private void setIssueReleases(Issue issue, com.atlassian.jira.rest.client.api.domain.Issue jiraIssue) { Iterable<Version> versions = jiraIssue.getFixVersions(); if (versions != null) { List<Release> releases = StreamSupport.stream(jiraIssue.getFixVersions().spliterator(), false) .map(version -> new Release(version.getName())) .collect(Collectors.toList()); issue.setReleases(releases); } }
private void updateStreamStatus(Issue issue, com.atlassian.jira.rest.client.api.domain.Issue jiraIssue, Map<String, Version> versionsMap, IssueInputBuilder inputBuilder) throws NotFoundException { String customField = JSON_CUSTOM_FIELD + TARGET_RELEASE; IssueField issueField = jiraIssue.getField(customField); if (issueField == null || (issueField.getType() == null && issueField.getValue() == null)) { String msg = String.format("Unable to set a stream status for issue %1$s as %2$s projects do not utilise field: %3$s", jiraIssue.getKey(), jiraIssue.getProject().getName(), customField); Utils.logWarnMessage(LOG, msg); return; } for (Map.Entry<String, FlagStatus> entry : issue.getStreamStatus().entrySet()) { if (entry.getValue() != FlagStatus.ACCEPTED) { String streamName = entry.getKey(); Version version = versionsMap.get(streamName); if (version != null) { inputBuilder.setFieldInput(new FieldInput(customField, ComplexIssueInputFieldValue.with("value", version.getId()))); } else { throw new NotFoundException("No Stream exists for this project with the name : " + streamName); } } } }
@Override public Version parse(JSONObject json) throws JSONException { final URI self = JsonParseUtil.getSelfUri(json); final Long id = JsonParseUtil.getOptionalLong(json, "id"); final String name = json.getString("name"); final String description = JsonParseUtil.getOptionalString(json, "description"); final boolean isArchived = json.getBoolean("archived"); final boolean isReleased = json.getBoolean("released"); final String releaseDateStr = JsonParseUtil.getOptionalString(json, "releaseDate"); final DateTime releaseDate = parseReleaseDate(releaseDateStr); return new Version(self, id, name, description, isArchived, isReleased, releaseDate); }