-
Notifications
You must be signed in to change notification settings - Fork 71
/
plugin.jsx
337 lines (318 loc) · 13.6 KB
/
plugin.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
import {graphql} from 'gatsby';
import React from 'react';
import PropTypes from 'prop-types';
import {cleanTitle} from '../commons/helper';
import Layout from '../layout';
import SEO from '../components/SEO';
import LineChart from '../components/LineChart';
import PluginDependencies from '../components/PluginDependencies';
import PluginLabels from '../components/PluginLabels';
import PluginLastReleased from '../components/PluginLastReleased';
import PluginActiveWarnings from '../components/PluginActiveWarnings';
import PluginInactiveWarnings from '../components/PluginInactiveWarnings';
import PluginGovernanceStatus from '../components/PluginGovernanceStatus';
import PluginDevelopers from '../components/PluginDevelopers';
import PluginReadableInstalls from '../components/PluginReadableInstalls';
import PluginIssues from '../components/PluginIssues';
import PluginReleases from '../components/PluginReleases';
import PluginIssueTrackers from '../components/PluginIssueTrackers';
function shouldShowWikiUrl({url}) {
return url?.startsWith('https://wiki.jenkins-ci.org') || url?.startsWith('https://wiki.jenkins.io') || url?.includes('github.com/jenkins-infra/plugins-wiki-docs');
}
function shouldShowGitHubUrl({url}) {
return url && url.startsWith('https://github.com');
}
const PluginWikiContent = ({wiki}) => {
if (wiki?.childHtmlRehype) {
return <div className="content" dangerouslySetInnerHTML={{__html: wiki.childHtmlRehype.html}} />;
}
return (<div className="content">
Documentation for this plugin is here:
{' '}
<a href={wiki.url}>{wiki.url}</a>
</div>);
};
PluginWikiContent.displayName = 'PluginWikiContent';
PluginWikiContent.propTypes = {
wiki: PropTypes.shape({
childHtmlRehype: PropTypes.shape({
html: PropTypes.string,
}),
url: PropTypes.string.isRequired
}).isRequired,
};
const switchTab = (tab) => {
const _paq = window._paq || [];
_paq.push(['trackEvent', 'Plugin Page', 'Click Tab', tab]);
};
const Tabs = ({tabs, selectedTab}) => {
// Tabs are client side only
// only render them on the client
// also forces gatsby to render based on hash
if (!global.window) { return null; }
return (
<ul className="nav nav-pills">
{tabs.map(tab => {
const isSelected = selectedTab === tab.id;
return (
<li className="nav-item" key={tab.id}>
<a className={`nav-link ${isSelected ? 'active' : ''}`} href={`#${tab.id}`} onClick={() => switchTab(tab.id)}>{tab.label}</a>
</li>
);
})}
</ul>
);
};
Tabs.displayName = 'Tabs';
Tabs.propTypes = {
tabs: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
})),
selectedTab: PropTypes.string.isRequired
};
export function useSelectedPluginTab(tabs) {
const tabName = global?.window?.location?.hash?.replace('#', '') || tabs[0].id;
return tabs.find(tab => tab.id === tabName) || tabs[0];
}
function PluginPage({data: {jenkinsPlugin: plugin, reverseDependencies: reverseDependencies, versions}}) {
const tabs = [
{id: 'documentation', label: 'Documentation'},
{id: 'releases', label: 'Releases'},
{id: 'issues', label: 'Issues'},
{id: 'dependencies', label: 'Dependencies'},
];
const selectedTab = useSelectedPluginTab(tabs);
const pluginPage = 'templates/plugin.jsx';
return (
<Layout id="pluginPage" reportProblemRelativeSourcePath={pluginPage} reportProblemTitle={plugin.title}
reportProblemUrl={plugin?.issueTrackers?.find(tracker => tracker.reportUrl)?.reportUrl || `/${plugin.name}`}>
<SEO title={cleanTitle(plugin.title)} description={plugin.excerpt} pathname={`/${plugin.name}`}/>
<div className="title-wrapper">
<h1 className="title">
{cleanTitle(plugin.title)}
</h1>
<div className="plugin-id">
{'ID: '}
{plugin.name}
</div>
</div>
<div className="row flex pluginContainer flex-column-reverse flex-md-row">
<div className="col-md-9 main">
<PluginActiveWarnings securityWarnings={plugin.securityWarnings} />
<PluginGovernanceStatus plugin={plugin} />
<Tabs tabs={tabs} selectedTab={selectedTab.id} />
<div>
{(function () {
if (selectedTab.id === 'releases') {
return <PluginReleases pluginId={plugin.name} versions={versions.edges.map(edge => edge.node)} />;
}
if (selectedTab.id === 'issues') {
return <PluginIssues pluginId={plugin.name} />;
}
if (selectedTab.id === 'dependencies') {
return (<PluginDependencies dependencies={plugin.dependencies}
reverseDependencies={reverseDependencies.edges.map(dep => dep.node)}
hasBomEntry={plugin.hasBomEntry}
gav={plugin.gav}/>);
}
return <PluginWikiContent wiki={plugin.wiki} />;
})()}
</div>
</div>
<div className="col-md-3 sidebar">
<h5>{`Version: ${plugin.version}`}</h5>
<PluginLastReleased buildDate={plugin.buildDate} releaseTimestamp={plugin.releaseTimestamp} />
<div>
{'Requires Jenkins '}
{plugin.requiredCore}
</div>
<div className="sidebarSection">
{plugin.stats && <h5>
{'Installs: '}
<PluginReadableInstalls currentInstalls={plugin.stats.currentInstalls} />
</h5>}
<div className="chart">
<LineChart
installations={plugin.stats.installations}
/>
</div>
<div className="label-link"><a href={`https://stats.jenkins.io/pluginversions/${plugin.name}.html`}>View detailed version information</a></div>
</div>
<div className="sidebarSection">
<h5>Links</h5>
{plugin.scm && <div className="label-link"><a href={plugin.scm}>GitHub</a></div>}
<PluginIssueTrackers issueTrackers={plugin.issueTrackers} />
{plugin.hasPipelineSteps && <div className="label-link"><a href={`https://www.jenkins.io/doc/pipeline/steps/${plugin.name}`}>Pipeline Step Reference</a></div>}
<div className="label-link"><a href={`https://javadoc.jenkins.io/plugin/${plugin.name}`}>Javadoc</a></div>
</div>
<div className="sidebarSection">
<h5>Labels</h5>
<PluginLabels labels={plugin.labels} />
</div>
<div className="sidebarSection">
<h5>Maintainers</h5>
<PluginDevelopers developers={plugin.developers} />
</div>
{shouldShowWikiUrl(plugin.wiki) &&
<div className="sidebarSection">
<h5>Help us improve this page!</h5>
{'This content is served from the '}
<a href={plugin.wiki.url} target="_wiki">Jenkins Wiki Export</a>
{' which is now '}
<a href="https://www.jenkins.io/blog/2021/09/04/wiki-attacked/" rel="noopener noreferrer" target="_blank">permanently offline</a>
{' and before that a '}
<a href="https://groups.google.com/forum/#!msg/jenkinsci-dev/lNmas8aBRrI/eL3u7A6qBwAJ" rel="noopener noreferrer" target="_blank">read-only state</a>
{'. We would love your help in moving plugin documentation to GitHub, see '}
<a href="https://jenkins.io/blog/2019/10/21/plugin-docs-on-github/" rel="noopener noreferrer" target="_blank">the guidelines</a>
{'.'}
</div>
}
{shouldShowGitHubUrl(plugin.wiki) &&
<div className="sidebarSection">
<h5>Help us improve this page!</h5>
{'To propose a change submit a pull request to '}
<a href={plugin.wiki.url} rel="noopener noreferrer" target="_blank">the plugin page</a>
{' on GitHub.'}
</div>
}
{plugin.securityWarnings &&
<div className="sidebarSection">
<PluginInactiveWarnings securityWarnings={plugin.securityWarnings} />
</div>
}
</div>
</div>
</Layout>
);
}
PluginPage.displayName = 'PluginPage';
PluginPage.propTypes = {
data: PropTypes.shape({
versions: PropTypes.shape({
edges: PropTypes.arrayOf(
PropTypes.shape({
node: PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
buildDate: PropTypes.string.isRequired,
requiredCore: PropTypes.string.isRequired,
sha1: PropTypes.string.isRequired,
sha256: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
version: PropTypes.string.isRequired,
})
})
)
}),
jenkinsPlugin: PropTypes.shape({
buildDate: PropTypes.string,
releaseTimestamp: PropTypes.string,
dependencies: PropTypes.arrayOf(PropTypes.shape({
name: PropTypes.string,
title: PropTypes.string,
optional: PropTypes.bool,
implied: PropTypes.bool,
version: PropTypes.string
})),
issueTrackers: PropTypes.arrayOf(PropTypes.shape({
viewUrl: PropTypes.string,
reportUrl: PropTypes.string,
})),
hasPipelineSteps: PropTypes.boolean,
excerpt: PropTypes.string,
gav: PropTypes.string.isRequired,
hasBomEntry: PropTypes.bool,
labels: PropTypes.arrayOf(PropTypes.string),
developers: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string,
name: PropTypes.string
})),
name: PropTypes.string.isRequired,
requiredCore: PropTypes.string,
scm: PropTypes.string,
securityWarnings: PropTypes.arrayOf(PropTypes.shape({
active: PropTypes.boolean,
id: PropTypes.string,
message: PropTypes.string,
url: PropTypes.string,
versions: PropTypes.arrayOf(PropTypes.shape({
firstVersion: PropTypes.string,
lastVersion: PropTypes.string,
}))
})),
sha1: PropTypes.string,
stats: PropTypes.shape({
currentInstalls: PropTypes.number.isRequired,
installations: PropTypes.arrayOf(PropTypes.shape({
timestamp: PropTypes.number,
total: PropTypes.number
}))
}).isRequired,
title: PropTypes.string.isRequired,
wiki: PropTypes.shape({
content: PropTypes.string,
url: PropTypes.string
}).isRequired,
version: PropTypes.string
}).isRequired,
reverseDependencies: PropTypes.shape({
edges: PropTypes.arrayOf(
PropTypes.shape({
node: PropTypes.shape({
dependentName: PropTypes.string.isRequired,
dependentTitle: PropTypes.string.isRequired,
optional: PropTypes.bool,
implied: PropTypes.bool,
})
})
)
})
}).isRequired
};
/* eslint no-undef: "off" */
export const pageQuery = graphql`
query PluginBySlug($name: String!) {
jenkinsPlugin(name: {eq: $name}) {
...JenkinsPluginFragment
}
versions: allJenkinsPluginVersion(filter: {name: {eq: $name}}, sort: {fields: buildDate, order: DESC}) {
edges {
node {
buildDate
compatibleSinceVersion
dependencies {
optional
name
version
}
id
name
requiredCore
sha1
sha256
url
version
}
}
}
reverseDependencies: allJenkinsPluginDependency(
filter: {
name: {eq: $name}
}
sort: {
fields: [dependentTitle]
order: ASC
}) {
edges {
node {
dependentTitle
dependentName
implied
optional
}
}
}
}
`;
export default PluginPage;