1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.changes.github;
20
21 import javax.inject.Inject;
22
23 import java.net.MalformedURLException;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Locale;
27 import java.util.Map;
28 import java.util.ResourceBundle;
29
30 import org.apache.maven.plugins.annotations.Mojo;
31 import org.apache.maven.plugins.annotations.Parameter;
32 import org.apache.maven.plugins.changes.AbstractChangesReport;
33 import org.apache.maven.plugins.changes.ProjectUtils;
34 import org.apache.maven.plugins.changes.issues.Issue;
35 import org.apache.maven.plugins.changes.issues.IssueUtils;
36 import org.apache.maven.plugins.changes.issues.IssuesReportHelper;
37 import org.apache.maven.plugins.changes.issues.IssuesReportRenderer;
38 import org.apache.maven.reporting.MavenReportException;
39 import org.apache.maven.settings.Settings;
40 import org.apache.maven.settings.crypto.SettingsDecrypter;
41
42
43
44
45
46
47
48 @Mojo(name = "github-changes", threadSafe = true)
49 public class GitHubChangesReport extends AbstractChangesReport {
50
51
52
53
54 private static final Map<String, Integer> GITHUB_COLUMNS = new HashMap<>();
55
56 static {
57 GITHUB_COLUMNS.put("Assignee", IssuesReportHelper.COLUMN_ASSIGNEE);
58 GITHUB_COLUMNS.put("Created", IssuesReportHelper.COLUMN_CREATED);
59 GITHUB_COLUMNS.put("Fix Version", IssuesReportHelper.COLUMN_FIX_VERSION);
60 GITHUB_COLUMNS.put("Id", IssuesReportHelper.COLUMN_ID);
61 GITHUB_COLUMNS.put("Reporter", IssuesReportHelper.COLUMN_REPORTER);
62 GITHUB_COLUMNS.put("Status", IssuesReportHelper.COLUMN_STATUS);
63 GITHUB_COLUMNS.put("Summary", IssuesReportHelper.COLUMN_SUMMARY);
64 GITHUB_COLUMNS.put("Type", IssuesReportHelper.COLUMN_TYPE);
65 GITHUB_COLUMNS.put("Updated", IssuesReportHelper.COLUMN_UPDATED);
66 }
67
68
69
70
71
72
73
74
75
76 @Parameter(defaultValue = "Id,Type,Summary,Assignee,Reporter,Status,Created,Updated,Fix Version")
77 private String columnNames;
78
79
80
81
82
83
84
85
86
87 @Parameter(defaultValue = "github")
88 private String githubAPIServerId;
89
90
91
92
93 @Parameter(defaultValue = "${settings}", readonly = true, required = true)
94 private Settings settings;
95
96
97
98
99 @Parameter(defaultValue = "true")
100 private boolean includeOpenIssues;
101
102
103
104
105 @Parameter(defaultValue = "true")
106 private boolean onlyMilestoneIssues;
107
108
109
110
111
112 @Parameter(defaultValue = "false")
113 private boolean onlyCurrentVersion;
114
115
116
117
118 private SettingsDecrypter settingsDecrypter;
119
120 @Inject
121 public GitHubChangesReport(SettingsDecrypter settingsDecrypter) {
122 this.settingsDecrypter = settingsDecrypter;
123 }
124
125
126
127
128
129 @Override
130 @Deprecated
131 public String getOutputName() {
132 return "github-changes";
133 }
134
135 @Override
136 public String getName(Locale locale) {
137 return getBundle(locale).getString("report.issues.name");
138 }
139
140 @Override
141 public String getDescription(Locale locale) {
142 return getBundle(locale).getString("report.issues.description");
143 }
144
145
146
147
148 @Override
149 public boolean canGenerateReport() {
150
151 if (runOnlyAtExecutionRoot && !isThisTheExecutionRoot()) {
152 getLog().info("Skipping the GitHub Report in this project because it's not the Execution Root");
153 return false;
154 }
155 String message = ProjectUtils.validateIssueManagement(project, "GitHub", "GitHub Report");
156 if (message != null) {
157 getLog().warn(message);
158 }
159 return message == null;
160 }
161
162 @Override
163 protected void executeReport(Locale locale) throws MavenReportException {
164
165
166 List<Integer> columnIds = IssuesReportHelper.getColumnIds(columnNames, GITHUB_COLUMNS);
167 if (columnIds.isEmpty()) {
168
169 throw new MavenReportException(
170 "maven-changes-plugin: None of the configured columnNames '" + columnNames + "' are valid.");
171 }
172
173 try {
174
175 GitHubDownloader issueDownloader = new GitHubDownloader(project, includeOpenIssues, onlyMilestoneIssues);
176
177 issueDownloader.configureAuthentication(settingsDecrypter, githubAPIServerId, settings, getLog());
178
179 List<Issue> issueList = issueDownloader.getIssueList();
180
181 if (onlyCurrentVersion) {
182 issueList = IssueUtils.getIssuesForVersion(issueList, project.getVersion());
183 getLog().info("The GitHub Report will contain issues only for the current version.");
184 }
185
186
187 IssuesReportRenderer report = new IssuesReportRenderer(getSink(), getBundle(locale), columnIds, issueList);
188 report.render();
189
190 } catch (MalformedURLException e) {
191
192 throw new MavenReportException("The Github URL is incorrect - " + e.getMessage());
193 } catch (Exception e) {
194 throw new MavenReportException(e.getMessage(), e);
195 }
196 }
197
198
199
200
201
202 private ResourceBundle getBundle(Locale locale) {
203 return ResourceBundle.getBundle("github-report", locale, this.getClass().getClassLoader());
204 }
205 }