/src/main/java/com/atlassian/jira/plugins/bitbucket/spi/bitbucket/BitbucketChangesetFileFactory.java
Java | 35 lines | 26 code | 3 blank | 6 comment | 0 complexity | e7cddfe22b05cb9d4ef77c10661e4834 MD5 | raw file
- package com.atlassian.jira.plugins.bitbucket.spi.bitbucket;
- import com.atlassian.jira.plugins.bitbucket.api.ChangesetFile;
- import com.atlassian.jira.plugins.bitbucket.api.ChangesetFileAction;
- import com.atlassian.jira.plugins.bitbucket.api.SourceControlException;
- import com.atlassian.jira.plugins.bitbucket.spi.DefaultBitbucketChangesetFile;
- import com.atlassian.jira.util.json.JSONException;
- import com.atlassian.jira.util.json.JSONObject;
- public class BitbucketChangesetFileFactory
- {
- /**
- * Parse the json object as a {@link ChangesetFile file} within a changeset.
- *
- * @param json the json object describing the file
- * @return the parsed {@link ChangesetFile}
- */
- public static ChangesetFile parse(JSONObject json)
- {
- try
- {
- JSONObject diffstatJson = json.getJSONObject("diffstat");
- return new DefaultBitbucketChangesetFile(
- ChangesetFileAction.valueOf(json.getString("type").toUpperCase()),
- json.getString("file"), diffstatJson.getInt("added"), diffstatJson.getInt("removed"));
- } catch (JSONException e)
- {
- throw new SourceControlException("invalid json object", e);
- }
- }
- private BitbucketChangesetFileFactory()
- {
- }
- }