title: Adding file to GitHub using java client - org.eclipse.egit.github.core
body: <p>I am trying to add a file to a repository using the below code but I am getting below error. I just want to add a file for now.</p>
  
  <blockquote>
    <p>org.eclipse.egit.github.core.client.RequestException: Invalid request.</p>
    
    <p>For 'properties/email', nil is not a string. For 'properties/name',
    nil is not a string. For 'properties/email', nil is not a string. For
    'properties/name', nil is not a string. (422)     at
    org.eclipse.egit.github.core.client.GitHubClient.createException(GitHubClient.java:552)
      at
    org.eclipse.egit.github.core.client.GitHubClient.sendJson(GitHubClient.java:643)
      at
    org.eclipse.egit.github.core.client.GitHubClient.post(GitHubClient.java:757)
      at
    org.eclipse.egit.github.core.service.DataService.createCommit(DataService.java:397)</p>
  </blockquote>
  
  <p>I sense that it is expecting some properties but how to supply this is not clear. What is that i am missing?</p>
  
  <p>Referring to <a href="https://gist.github.com/Detelca/2337731" rel="nofollow noreferrer">https://gist.github.com/Detelca/2337731</a></p>
  
  <pre><code>import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.Collection;
  import java.util.Date;
  import java.util.List;
  
  import org.eclipse.egit.github.core.Blob;
  import org.eclipse.egit.github.core.Commit;
  import org.eclipse.egit.github.core.CommitUser;
  import org.eclipse.egit.github.core.Reference;
  import org.eclipse.egit.github.core.Repository;
  import org.eclipse.egit.github.core.RepositoryCommit;
  import org.eclipse.egit.github.core.Tree;
  import org.eclipse.egit.github.core.TreeEntry;
  import org.eclipse.egit.github.core.TypedResource;
  import org.eclipse.egit.github.core.User;
  import org.eclipse.egit.github.core.client.GitHubClient;
  import org.eclipse.egit.github.core.service.CommitService;
  import org.eclipse.egit.github.core.service.DataService;
  import org.eclipse.egit.github.core.service.RepositoryService;
  import org.eclipse.egit.github.core.service.UserService;
  
  public class GHWriter {
  
  public static void main(String[] args) {
      try {
          new GHWriter().writeFile("test_two.txt", "test content");
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  //https://gist.github.com/Detelca/2337731
  public boolean writeFile(String fileName, String fileContent) throws IOException{
      // initialize github client
      GitHubClient client = new GitHubClient();
      //TextView password = (TextView)findViewById(R.id.textViewPassword);
      client.setCredentials("username", "password");
  
      // create needed services
      RepositoryService repositoryService = new RepositoryService();
      CommitService commitService = new CommitService(client);
      DataService dataService = new DataService(client);
  
      // get some sha's from current state in git
      Repository repository =  repositoryService.getRepository("username", "repositoryName");
      String baseCommitSha = repositoryService.getBranches(repository).get(0).getCommit().getSha();
      RepositoryCommit baseCommit = commitService.getCommit(repository, baseCommitSha);
      String treeSha = baseCommit.getSha();
  
      // create new blob with data
      Blob blob = new Blob();
          blob.setContent("[\"" + System.currentTimeMillis() + "\"]").setEncoding(Blob.ENCODING_UTF8);
      String blob_sha = dataService.createBlob(repository, blob);
      Tree baseTree = dataService.getTree(repository, treeSha);
  
      // create new tree entry
      TreeEntry treeEntry = new TreeEntry();
      treeEntry.setPath("testfile.txt");
      treeEntry.setMode(TreeEntry.MODE_BLOB);
      treeEntry.setType(TreeEntry.TYPE_BLOB);
      treeEntry.setSha(blob_sha);
      treeEntry.setSize(blob.getContent().length());
      Collection&lt;TreeEntry&gt; entries = new ArrayList&lt;TreeEntry&gt;();
      entries.add(treeEntry);
      Tree newTree = dataService.createTree(repository, entries, baseTree.getSha());
  
      // create commit
      Commit commit = new Commit();
          commit.setMessage("first commit at " + new Date(System.currentTimeMillis()).toLocaleString());
      commit.setTree(newTree);
  
      UserService userService = new UserService( client );
      User user = userService.getUser();
      CommitUser author = new CommitUser();
      author.setName( user.getName() );
      Calendar now = Calendar.getInstance();
      author.setDate(now.getTime());
      commit.setAuthor(author);
      commit.setCommitter(author);
  
  
      List&lt;Commit&gt; listOfCommits = new ArrayList&lt;Commit&gt;();
      listOfCommits.add(new Commit().setSha(baseCommitSha));
      // listOfCommits.containsAll(base_commit.getParents());
      commit.setParents(listOfCommits);
      // commit.setSha(base_commit.getSha());
      Commit newCommit = dataService.createCommit(repository, commit);
  
      // create resource
      TypedResource commitResource = new TypedResource();
      commitResource.setSha(newCommit.getSha());
      commitResource.setType(TypedResource.TYPE_COMMIT);
      commitResource.setUrl(newCommit.getUrl());
  
      // get master reference and update it
      Reference reference = dataService.getReference(repository, "heads/master");
          reference.setObject(commitResource);
          dataService.editReference(repository, reference, true);
          System.out.println("Committed URL: "+ newCommit.getUrl());
      return false;    
  }
  
  }
  </code></pre>
  
  <p>Thanks</p>