PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/atlassian/jira/plugins/bitbucket/spi/bitbucket/BitbucketChangesetFileFactory.java

https://bitbucket.org/atlassian/jira-bitbucket-connector/
Java | 35 lines | 26 code | 3 blank | 6 comment | 0 complexity | e7cddfe22b05cb9d4ef77c10661e4834 MD5 | raw file
  1. package com.atlassian.jira.plugins.bitbucket.spi.bitbucket;
  2. import com.atlassian.jira.plugins.bitbucket.api.ChangesetFile;
  3. import com.atlassian.jira.plugins.bitbucket.api.ChangesetFileAction;
  4. import com.atlassian.jira.plugins.bitbucket.api.SourceControlException;
  5. import com.atlassian.jira.plugins.bitbucket.spi.DefaultBitbucketChangesetFile;
  6. import com.atlassian.jira.util.json.JSONException;
  7. import com.atlassian.jira.util.json.JSONObject;
  8. public class BitbucketChangesetFileFactory
  9. {
  10. /**
  11. * Parse the json object as a {@link ChangesetFile file} within a changeset.
  12. *
  13. * @param json the json object describing the file
  14. * @return the parsed {@link ChangesetFile}
  15. */
  16. public static ChangesetFile parse(JSONObject json)
  17. {
  18. try
  19. {
  20. JSONObject diffstatJson = json.getJSONObject("diffstat");
  21. return new DefaultBitbucketChangesetFile(
  22. ChangesetFileAction.valueOf(json.getString("type").toUpperCase()),
  23. json.getString("file"), diffstatJson.getInt("added"), diffstatJson.getInt("removed"));
  24. } catch (JSONException e)
  25. {
  26. throw new SourceControlException("invalid json object", e);
  27. }
  28. }
  29. private BitbucketChangesetFileFactory()
  30. {
  31. }
  32. }