Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 GitHub Inc. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: Kevin Sawicki (GitHub Inc.) - initial API and implementation /
 
 package org.eclipse.egit.github.core.service;
 
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_COMMENTS;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_EVENTS;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_ISSUES;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOS;
 import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_FIRST;
 import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_SIZE;
 
 
 import java.util.List;
 import java.util.Map;
 
Issue service class for listing, searching, and fetching org.eclipse.egit.github.core.Issue objects using a org.eclipse.egit.github.core.client.GitHubClient.

See also:
GitHub Issues API documentation
 
 public class IssueService extends GitHubService {

Filter field key
 
 	public static final String FIELD_FILTER = "filter"//$NON-NLS-1$
 
Filter by issue assignee
 
 	public static final String FILTER_ASSIGNEE = "assignee"//$NON-NLS-1$
 
Filter by issue's milestone
 
 	public static final String FILTER_MILESTONE = "milestone"//$NON-NLS-1$
 
Filter by user mentioned in issue
 
 	public static final String FILTER_MENTIONED = "mentioned"//$NON-NLS-1$
 
Filter by subscribed issues for user
 
 	public static final String FILTER_SUBSCRIBED = "subscribed"//$NON-NLS-1$
 
Filter by created issues by user
 
 	public static final String FILTER_CREATED = "created"//$NON-NLS-1$
 
Filter by assigned issues for user
 
 	public static final String FILTER_ASSIGNED = "assigned"//$NON-NLS-1$
 
Filter by issue's labels
 
 	public static final String FILTER_LABELS = "labels"//$NON-NLS-1$
 
Filter by issue's state
 
 	public static final String FILTER_STATE = "state"//$NON-NLS-1$
 
Issue open state filter value
 
 	public static final String STATE_OPEN = "open"//$NON-NLS-1$
 
Issue closed state filter value
	public static final String STATE_CLOSED = "closed"//$NON-NLS-1$
Issue body field name
	public static final String FIELD_BODY = "body"//$NON-NLS-1$
Issue title field name
	public static final String FIELD_TITLE = "title"//$NON-NLS-1$
Since date field
	public static final String FIELD_SINCE = "since"//$NON-NLS-1$
Sort direction of output
	public static final String FIELD_DIRECTION = "direction"//$NON-NLS-1$
Ascending direction sort order
	public static final String DIRECTION_ASCENDING = "asc"//$NON-NLS-1$
Descending direction sort order
	public static final String DIRECTION_DESCENDING = "desc"//$NON-NLS-1$
Sort field key
	public static final String FIELD_SORT = "sort"//$NON-NLS-1$
Sort by created at
	public static final String SORT_CREATED = "created"//$NON-NLS-1$
Sort by updated at
	public static final String SORT_UPDATED = "updated"//$NON-NLS-1$
Sort by commented on at
	public static final String SORT_COMMENTS = "comments"//$NON-NLS-1$
Create issue service
	public IssueService() {
		super();
	}

Create issue service

Parameters:
client cannot be null
	public IssueService(GitHubClient client) {
		super(client);
	}

Get issues for currently authenticated user

Returns:
non-null but possibly empty list of issues
Throws:
java.io.IOException
	public List<IssuegetIssues() throws IOException {
		return getIssues(null);
	}

Get issues for currently authenticated user

Parameters:
filterData
Returns:
non-null but possibly empty list of issues
Throws:
java.io.IOException
	public List<IssuegetIssues(Map<StringStringfilterData)
			throws IOException {
		return getAll(pageIssues(filterData));
	}

Page issues for currently authenticated user

Returns:
iterator over pages of issues
		return pageIssues(null);
	}

Page issues for currently authenticated user

Parameters:
filterData
Returns:
iterator over pages of issues
	public PageIterator<IssuepageIssues(Map<StringStringfilterData) {
		return pageIssues(filterData);
	}

Page issues for currently authenticated user

Parameters:
filterData
size
Returns:
iterator over pages of issues
	public PageIterator<IssuepageIssues(Map<StringStringfilterData,
			int size) {
		return pageIssues(filterDatasize);
	}

Page issues for currently authenticated user

Parameters:
filterData
start
size
Returns:
iterator over pages of issues
	public PageIterator<IssuepageIssues(Map<StringStringfilterData,
			int startint size) {
		PagedRequest<Issuerequest = createPagedRequest(startsize);
		request.setParams(filterData);
		request.setType(new TypeToken<List<Issue>>() {
		}.getType());
		return createPageIterator(request);
	}

Get issue

Parameters:
user
repository
id
Returns:
issue
Throws:
java.io.IOException
	public Issue getIssue(String userString repositoryint id)
			throws IOException {
		return getIssue(userrepository, Integer.toString(id));
	}

Get issue

Parameters:
user
repository
id
Returns:
issue
Throws:
java.io.IOException
	public Issue getIssue(String userString repositoryString id)
			throws IOException {
		verifyRepository(userrepository);
		if (id == null)
			throw new IllegalArgumentException("Id cannot be null"); //$NON-NLS-1$
		if (id.length() == 0)
			throw new IllegalArgumentException("Id cannot be empty"); //$NON-NLS-1$
		uri.append('/').append(user).append('/').append(repository);
		uri.append('/').append(id);
		request.setUri(uri);
		request.setType(Issue.class);
		return (Issue.get(request).getBody();
	}

Get an issue's comments

Parameters:
user
repository
id
Returns:
list of comments
Throws:
java.io.IOException
	public List<CommentgetComments(String userString repositoryint id)
			throws IOException {
		return getComments(userrepository, Integer.toString(id));
	}

Get an issue's comments

Parameters:
user
repository
id
Returns:
list of comments
Throws:
java.io.IOException
	public List<CommentgetComments(String userString repositoryString id)
			throws IOException {
		verifyRepository(userrepository);
		if (id == null)
			throw new IllegalArgumentException("Id cannot be null"); //$NON-NLS-1$
		if (id.length() == 0)
			throw new IllegalArgumentException("Id cannot be empty"); //$NON-NLS-1$
		uri.append('/').append(user).append('/').append(repository);
		uri.append('/').append(id);
		request.setUri(uri);
		request.setType(new TypeToken<List<Comment>>() {
		}.getType());
		return getAll(request);
	}

Get bulk issues request

Parameters:
user
repository
filterData
start
size
Returns:
paged request
			String repositoryMap<StringStringfilterDataint start,
			int size) {
		verifyRepository(userrepository);
		uri.append('/').append(user).append('/').append(repository);
		PagedRequest<Issuerequest = createPagedRequest(startsize);
		request.setParams(filterData).setUri(uri);
		request.setType(new TypeToken<List<Issue>>() {
		}.getType());
		return request;
	}

Get a list of org.eclipse.egit.github.core.Issue objects that match the specified filter data

Parameters:
user
repository
filterData
Returns:
list of issues
Throws:
java.io.IOException
	public List<IssuegetIssues(String userString repository,
			Map<StringStringfilterDatathrows IOException {
		PagedRequest<Issuerequest = createIssuesRequest(userrepository,
				filterData);
		return getAll(request);
	}

Get page iterator over issues query

Parameters:
user
repository
Returns:
iterator over issue pages
	public PageIterator<IssuepageIssues(String userString repository) {
		return pageIssues(userrepositorynull);
	}

Get page iterator over issues query

Parameters:
user
repository
filterData
Returns:
iterator
	public PageIterator<IssuepageIssues(String userString repository,
			Map<StringStringfilterData) {
		return pageIssues(userrepositoryfilterData);
	}

Get page iterator over issues query

Parameters:
user
repository
filterData
size
Returns:
iterator
	public PageIterator<IssuepageIssues(String userString repository,
			Map<StringStringfilterDataint size) {
		return pageIssues(userrepositoryfilterDatasize);
	}

Get page iterator over issues query

Parameters:
user
repository
filterData
size page size
start starting page number
Returns:
iterator
	public PageIterator<IssuepageIssues(String userString repository,
			Map<StringStringfilterDataint startint size) {
		PagedRequest<Issuerequest = createIssuesRequest(userrepository,
				filterDatastartsize);
		return createPageIterator(request);
	}

Create issue map for issue

Parameters:
issue
newIssue
Returns:
map
	protected Map<ObjectObjectcreateIssueMap(Issue issueboolean newIssue) {
		Map<ObjectObjectparams = new HashMap<ObjectObject>();
		if (issue != null) {
			params.put(issue.getBody());
			params.put(issue.getTitle());
			User assignee = issue.getAssignee();
			if (assignee != null)
				params.put(assignee.getName());
			Milestone milestone = issue.getMilestone();
			if (milestone != null) {
				int number = milestone.getNumber();
				if (number > 0)
					params.put(, Integer.toString(number));
				else {
					if (!newIssue)
						params.put(null);
				}
			}
			List<Labellabels = issue.getLabels();
			if (labels != null) {
				List<StringlabelNames = new ArrayList<String>(labels.size());
				for (Label label : labels)
					labelNames.add(label.getName());
				params.put(labelNames);
			}
		}
		return params;
	}

Create issue

Parameters:
user
repository
issue
Returns:
created issue
Throws:
java.io.IOException
	public Issue createIssue(String userString repositoryIssue issue)
			throws IOException {
		verifyRepository(userrepository);
		uri.append('/').append(user).append('/').append(repository);
		Map<ObjectObjectparams = createIssueMap(issuetrue);
		return .post(uri.toString(), paramsIssue.class);
	}

Edit issue

Parameters:
user
repository
issue
Returns:
created issue
Throws:
java.io.IOException
	public Issue editIssue(String userString repositoryIssue issue)
			throws IOException {
		verifyRepository(userrepository);
		if (issue == null)
			throw new IllegalArgumentException("Issue cannot be null"); //$NON-NLS-1$
		uri.append('/').append(user).append('/').append(repository);
		uri.append('/').append(issue.getNumber());
		Map<ObjectObjectparams = createIssueMap(issuefalse);
		String state = issue.getState();
		if (state != null)
			params.put(state);
		return .post(uri.toString(), paramsIssue.class);
	}

Create comment on specified issue id

Parameters:
user
repository
issueId
comment
Returns:
created issue
Throws:
java.io.IOException
	public Comment createComment(String userString repositoryint issueId,
			String commentthrows IOException {
		return createComment(userrepository, Integer.toString(issueId),
				comment);
	}

Create comment on specified issue id

Parameters:
user
repository
issueId
comment
Returns:
created issue
Throws:
java.io.IOException
	public Comment createComment(String userString repository,
			String issueIdString commentthrows IOException {
		verifyRepository(userrepository);
		if (issueId == null)
			throw new IllegalArgumentException("Issue id cannot be null"); //$NON-NLS-1$
		if (issueId.length() == 0)
			throw new IllegalArgumentException("Issue id cannot be empty"); //$NON-NLS-1$
		uri.append('/').append(user).append('/').append(repository);
		uri.append('/').append(issueId);
		Map<StringStringparams = new HashMap<StringString>(1, 1);
		params.put(comment);
		return .post(uri.toString(), paramsComment.class);
	}

Get issue comment

Parameters:
user
repository
commentId
Returns:
comment
Throws:
java.io.IOException
	public Comment getComment(String userString repositorylong commentId)
			throws IOException {
		verifyRepository(userrepository);
		uri.append('/').append(user).append('/').append(repository);
		uri.append('/').append(commentId);
		request.setUri(uri);
		request.setType(Comment.class);
		return (Comment.get(request).getBody();
	}

Edit issue comment

Parameters:
user
repository
comment
Returns:
edited comment
Throws:
java.io.IOException
	public Comment editComment(String userString repositoryComment comment)
			throws IOException {
		verifyRepository(userrepository);
		if (comment == null)
			throw new IllegalArgumentException("Comment cannot be null"); //$NON-NLS-1$
		uri.append('/').append(user).append('/').append(repository);
		uri.append('/').append(comment.getId());
		return .post(uri.toString(), commentComment.class);
	}

Delete the issue comment with the given id

Parameters:
user
repository
commentId
Throws:
java.io.IOException
	public void deleteComment(String userString repositorylong commentId)
			throws IOException {
		deleteComment(userrepository, Long.toString(commentId));
	}

Delete the issue comment with the given id

Parameters:
user
repository
commentId
Throws:
java.io.IOException
	public void deleteComment(String userString repositoryString commentId)
			throws IOException {
		verifyRepository(userrepository);
		if (commentId == null)
			throw new IllegalArgumentException("Comment cannot be null"); //$NON-NLS-1$
		if (commentId.length() == 0)
			throw new IllegalArgumentException("Comment cannot be empty"); //$NON-NLS-1$
		uri.append('/').append(user).append('/').append(repository);
		uri.append('/').append(commentId);
	}

Page issue events for repository

Parameters:
user
repository
Returns:
iterator over issue event pages
Throws:
java.io.IOException
	public PageIterator<IssueEventpageEvents(String userString repository)
			throws IOException {
		return pageEvents(userrepository);
	}

Page issue events for repository

Parameters:
user
repository
size
Returns:
iterator over issue event pages
Throws:
java.io.IOException
	public PageIterator<IssueEventpageEvents(String userString repository,
			int sizethrows IOException {
		return pageEvents(userrepositorysize);
	}

Page events for issue in repository

Parameters:
user
repository
start
size
Returns:
iterator over issue event pages
Throws:
java.io.IOException
	public PageIterator<IssueEventpageEvents(String userString repository,
			int startint sizethrows IOException {
		verifyRepository(userrepository);
		PagedRequest<IssueEventrequest = createPagedRequest(startsize);
		uri.append('/').append(user).append('/').append(repository);
		request.setUri(uri);
		request.setType(new TypeToken<List<IssueEvent>>() {
		}.getType());
		return createPageIterator(request);
	}

Page events for issue in repository

Parameters:
user
repository
issueId
Returns:
iterator over issue event pages
Throws:
java.io.IOException
			String repositoryint issueIdthrows IOException {
		return pageIssueEvents(userrepositoryissueId);
	}

Page events for issue in repository

Parameters:
user
repository
issueId
size
Returns:
iterator over issue event pages
Throws:
java.io.IOException
			String repositoryint issueIdint sizethrows IOException {
		return pageIssueEvents(userrepositoryissueIdsize);
	}

Page issue events for repository

Parameters:
user
repository
issueId
start
size
Returns:
iterator over issue event pages
Throws:
java.io.IOException
			String repositoryint issueIdint startint size)
			throws IOException {
		verifyRepository(userrepository);
		PagedRequest<IssueEventrequest = createPagedRequest(startsize);
		uri.append('/').append(user).append('/').append(repository);
		uri.append('/').append(issueId);
		request.setUri(uri);
		request.setType(new TypeToken<List<IssueEvent>>() {
		}.getType());
		return createPageIterator(request);
	}

Get issue event for repository

Parameters:
user
repository
eventId
Returns:
iterator over issue event pages
Throws:
java.io.IOException
	public IssueEvent getIssueEvent(String userString repositorylong eventId)
			throws IOException {
		verifyRepository(userrepository);
		uri.append('/').append(user).append('/').append(repository);
		uri.append('/').append(eventId);
		request.setUri(uri);
		request.setType(IssueEvent.class);
		return (IssueEvent.get(request).getBody();
	}
New to GrepCode? Check out our FAQ X