@Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.m_edit:
       if (issue != null)
         startActivityForResult(
             EditIssueActivity.createIntent(
                 issue, repositoryId.getOwner(), repositoryId.getName(), user),
             ISSUE_EDIT);
       return true;
     case R.id.m_comment:
       if (issue != null)
         startActivityForResult(
             CreateCommentActivity.createIntent(repositoryId, issueNumber, user), COMMENT_CREATE);
       return true;
     case R.id.m_refresh:
       refreshIssue();
       return true;
     case R.id.m_share:
       if (issue != null) shareIssue();
       return true;
     case R.id.m_state:
       if (issue != null) stateTask.confirm(STATE_OPEN.equals(issue.getState()));
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
Ejemplo n.º 2
0
 /**
  * Get repository and throw a {@link MojoExecutionException} on failures
  *
  * @param project
  * @param owner
  * @param name
  * @return non-null repository id
  * @throws MojoExecutionException
  */
 protected RepositoryId getRepository(
     final MavenProject project, final String owner, final String name)
     throws MojoExecutionException {
   RepositoryId repository = RepositoryUtils.getRepository(project, owner, name);
   if (repository == null)
     throw new MojoExecutionException("No GitHub repository (owner and name) configured");
   if (isDebug())
     debug(MessageFormat.format("Using GitHub repository {0}", repository.generateId()));
   return repository;
 }
Ejemplo n.º 3
0
  public static boolean repositoryExists(
      RepositoryService repositoryService, RepositoryId repositoryId) throws IOException {
    List<Repository> repositories = repositoryService.getRepositories(repositoryId.getOwner());

    for (Repository repository : repositories) {
      if (repository.generateId().equals(repositoryId.generateId())) {
        return true;
      }
    }

    return false;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle args = getArguments();
    repositoryId =
        RepositoryId.create(
            args.getString(EXTRA_REPOSITORY_OWNER), args.getString(EXTRA_REPOSITORY_NAME));
    issueNumber = args.getInt(EXTRA_ISSUE_NUMBER);
    user = (User) args.getSerializable(EXTRA_USER);
    isCollaborator = args.getBoolean(EXTRA_IS_COLLABORATOR, false);

    DialogFragmentActivity dialogActivity = (DialogFragmentActivity) getActivity();

    milestoneTask =
        new EditMilestoneTask(dialogActivity, repositoryId, issueNumber) {

          @Override
          protected void onSuccess(Issue editedIssue) throws Exception {
            super.onSuccess(editedIssue);

            updateHeader(editedIssue);
          }
        };

    assigneeTask =
        new EditAssigneeTask(dialogActivity, repositoryId, issueNumber) {

          @Override
          protected void onSuccess(Issue editedIssue) throws Exception {
            super.onSuccess(editedIssue);

            updateHeader(editedIssue);
          }
        };

    labelsTask =
        new EditLabelsTask(dialogActivity, repositoryId, issueNumber) {

          @Override
          protected void onSuccess(Issue editedIssue) throws Exception {
            super.onSuccess(editedIssue);

            updateHeader(editedIssue);
          }
        };

    stateTask =
        new EditStateTask(dialogActivity, repositoryId, issueNumber) {

          @Override
          protected void onSuccess(Issue editedIssue) throws Exception {
            super.onSuccess(editedIssue);

            updateHeader(editedIssue);
          }
        };
  }
  @Override
  public IStatus performQuery(
      TaskRepository repository,
      IRepositoryQuery query,
      TaskDataCollector collector,
      ISynchronizationSession session,
      IProgressMonitor monitor) {
    IStatus result = Status.OK_STATUS;
    List<String> statuses = QueryUtils.getAttributes(IssueService.FILTER_STATE, query);

    monitor.beginTask(Messages.PullRequestConnector_TaskFetching, statuses.size());
    try {
      RepositoryId repo = getRepository(repository.getRepositoryUrl());

      GitHubClient client = IssueConnector.createClient(repository);
      PullRequestService service = new PullRequestService(client);
      IssueService commentService = new IssueService(client);

      for (String status : statuses) {
        List<PullRequest> pulls = service.getPullRequests(repo, status);

        // collect task data
        for (PullRequest pr : pulls) {
          pr = service.getPullRequest(repo, pr.getNumber());
          PullRequestComposite prComp = new PullRequestComposite();
          prComp.setRequest(pr);
          List<Comment> comments = null;
          if (pr.getComments() > 0)
            comments =
                commentService.getComments(
                    repo.getOwner(), repo.getName(), Integer.toString(pr.getNumber()));
          if (pr.getCommits() > 0) prComp.setCommits(service.getCommits(repo, pr.getNumber()));
          TaskData taskData =
              taskDataHandler.createTaskData(repository, monitor, repo, prComp, comments);
          collector.accept(taskData);
        }
        monitor.worked(1);
      }
    } catch (IOException e) {
      result = GitHub.createWrappedStatus(e);
    }

    monitor.done();
    return result;
  }
Ejemplo n.º 6
0
  public static RepositoryId parseRepositoryFromUrl(String repositoryUrl) {
    String prefix = "*****@*****.**";

    if (repositoryUrl.startsWith(prefix)) {
      String[] parts = repositoryUrl.split(":");

      parts = parts[1].split("/");

      String owner = parts[0];
      String name = parts[1];
      if (name.endsWith(".git")) {
        name = name.replace(".git", "");
      }
      return RepositoryId.create(owner, name);
    }

    return RepositoryId.createFromUrl(repositoryUrl);
  }
  @Override
  public TaskData getTaskData(TaskRepository repository, String taskId, IProgressMonitor monitor)
      throws CoreException {
    RepositoryId repo = getRepository(repository.getRepositoryUrl());

    try {
      GitHubClient client = IssueConnector.createClient(repository);
      PullRequestService service = new PullRequestService(client);
      PullRequest pr = service.getPullRequest(repo, Integer.parseInt(taskId));
      PullRequestComposite prComp = new PullRequestComposite();
      prComp.setRequest(pr);
      IssueService commentService = new IssueService(client);
      List<Comment> comments = null;
      if (pr.getComments() > 0)
        comments = commentService.getComments(repo.getOwner(), repo.getName(), taskId);
      if (pr.getCommits() > 0) prComp.setCommits(service.getCommits(repo, pr.getNumber()));
      return taskDataHandler.createTaskData(repository, monitor, repo, prComp, comments);
    } catch (IOException e) {
      throw new CoreException(GitHub.createWrappedStatus(e));
    }
  }
 private void shareIssue() {
   String id = repositoryId.generateId();
   if (IssueUtils.isPullRequest(issue))
     startActivity(
         ShareUtils.create(
             "Pull Request " + issueNumber + " on " + id,
             "https://github.com/" + id + "/pull/" + issueNumber));
   else
     startActivity(
         ShareUtils.create(
             "Issue " + issueNumber + " on " + id,
             "https://github.com/" + id + "/issues/" + issueNumber));
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    issueNumber = getIntExtra(EXTRA_ISSUE_NUMBER);
    comment = getSerializableExtra(EXTRA_COMMENT);
    repositoryId =
        new RepositoryId(
            getStringExtra(EXTRA_REPOSITORY_OWNER), getStringExtra(EXTRA_REPOSITORY_NAME));

    super.onCreate(savedInstanceState);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle(getString(R.string.issue_title) + issueNumber);
    actionBar.setSubtitle(repositoryId.generateId());
    avatars.bind(actionBar, (User) getSerializableExtra(EXTRA_USER));
  }
  /**
   * Request an image using the contents API if the source URI is a path to a file already in the
   * repository
   *
   * @param source
   * @return
   * @throws IOException
   */
  private Drawable requestRepositoryImage(final String source) throws IOException {
    if (TextUtils.isEmpty(source)) return null;

    Uri uri = Uri.parse(source);
    if (!HOST_DEFAULT.equals(uri.getHost())) return null;

    List<String> segments = uri.getPathSegments();
    if (segments.size() < 5) return null;

    String prefix = segments.get(2);
    // Two types of urls supported:
    // github.com/github/android/raw/master/app/res/drawable-xhdpi/app_icon.png
    // github.com/github/android/blob/master/app/res/drawable-xhdpi/app_icon.png?raw=true
    if (!("raw".equals(prefix)
        || ("blob".equals(prefix) && !TextUtils.isEmpty(uri.getQueryParameter("raw")))))
      return null;

    String owner = segments.get(0);
    if (TextUtils.isEmpty(owner)) return null;
    String name = segments.get(1);
    if (TextUtils.isEmpty(name)) return null;
    String branch = segments.get(3);
    if (TextUtils.isEmpty(branch)) return null;

    StringBuilder path = new StringBuilder(segments.get(4));
    for (int i = 5; i < segments.size(); i++) {
      String segment = segments.get(i);
      if (!TextUtils.isEmpty(segment)) path.append('/').append(segment);
    }

    if (TextUtils.isEmpty(path)) return null;

    List<RepositoryContents> contents =
        service.getContents(RepositoryId.create(owner, name), path.toString(), branch);
    if (contents != null && contents.size() == 1) {
      byte[] content = Base64.decode(contents.get(0).getContent(), DEFAULT);
      Bitmap bitmap = ImageUtils.getBitmap(content, width, MAX_VALUE);
      if (bitmap == null) return loading.getDrawable(source);
      BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
      drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
      return drawable;
    } else return null;
  }
Ejemplo n.º 11
0
 /**
  * Add repository id to intent being built up
  *
  * @param repositoryId
  * @return this builder
  */
 public Builder repo(RepositoryId repositoryId) {
   return add(EXTRA_REPOSITORY_NAME, repositoryId.getName())
       .add(EXTRA_REPOSITORY_OWNER, repositoryId.getOwner());
 }
Ejemplo n.º 12
0
 /**
  * Resolve the {@link RepositoryId} referenced by the given intent
  *
  * @param intent
  * @return repository id
  */
 public static RepositoryId repoFrom(Intent intent) {
   String repoName = intent.getStringExtra(EXTRA_REPOSITORY_NAME);
   String repoOwner = intent.getStringExtra(EXTRA_REPOSITORY_OWNER);
   return RepositoryId.create(repoOwner, repoName);
 }
 private String getFileName() {
   return PATH + "/" + repoInfo.getOwner() + "/" + repoInfo.getName();
 }
 private void createPath() {
   final String path = PATH + "/" + repoInfo.getOwner();
   new File(path).mkdirs();
 }
Ejemplo n.º 15
0
  public static boolean repositoryExists(
      RepositoryService repositoryService, String user, String repositoryName) throws IOException {
    RepositoryId repositoryId = RepositoryId.create(user, repositoryName);

    return repositoryExists(repositoryService, repositoryId);
  }