This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
refresh-references-doc.pl
executable file
·147 lines (115 loc) · 3.92 KB
/
refresh-references-doc.pl
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
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Path qw(make_path);
use Pod::Markdown;
use Git::Repository;
my $tmpDir = "/home/goneri/fusioninventory/tmp/wikigit";
my @repoList = (
{
name => 'agent',
url =>
'git+ssh://forge.fusioninventory.org/git/fusioninventory/agent.git',
branches => [
{
serie => '2.1.x',
branch => '2.1.x',
status => 'oldstable'
},
{
serie => '2.2.x',
branch => '2.2.x',
status => 'stable'
},
{
'serie' => '2.3.x',
'branch' => '2.3.x',
'status' => 'dev',
},
{
'serie' => '3.0.x',
'branch' => 'master',
'status' => 'dev'
},
],
files => [
'fusioninventory-agent', 'fusioninventory-injector',
'fusioninventory-inventory'
]
},
{
name => 'agent-task-esx',
url =>
'git+ssh://forge.fusioninventory.org/git/fusioninventory/agent-task-esx.git',
branches => [
{
serie => '2.x',
branch => 'master',
status => 'stable'
}
],
files => [
'fusioninventory-esx'
]
},
{
name => 'agent-task-network',
url =>
'git+ssh://forge.fusioninventory.org/git/fusioninventory/agent-task-network.git',
branches => [
{
serie => '1.0.x',
branch => 'master',
status => 'stable'
}
],
files => [
'fusioninventory-netdiscovery', 'fusioninventory-netinventory'
]
},
);
my $indexContent = "# Reference documentation\n";
my $wiki = Git::Repository->new( work_tree => '.' );
eval { $wiki->run('rm', '-rf', "documentation/references") };
foreach my $repo (@repoList) {
my $localDir = sprintf( "%s/%s", $tmpDir, $repo->{name} );
if ( !-d $localDir && !make_path($localDir) ) {
die "mkdir failed\n";
}
if ( !-d "$localDir/.git" ) {
Git::Repository->run( 'clone' => $repo->{url}, $localDir );
}
my $r = Git::Repository->new( work_tree => $localDir );
$r->run( 'fetch', 'origin' );
foreach my $file ( @{ $repo->{files} } ) {
$indexContent .= "\n## $file\n\n";
foreach my $branch ( @{ $repo->{branches} } ) {
my $content =
eval{ $r->run( 'show', 'origin/' . $branch->{branch} . ':' . $file ) };
open TMP, ">$localDir/tmpfile" or die;
print TMP $content;
close TMP;
my $mdwnFile = sprintf("documentation/references/%s/%s/%s", $repo->{name}, $branch->{serie}, $file);
print $mdwnFile. "\n";
next unless $content;
my $parser = Pod::Markdown->new;
$parser->parse_from_file("$localDir/tmpfile");
make_path( dirname( $mdwnFile . '.mdwn' ) );
open OUT, ">" . $mdwnFile . '.mdwn' or die "$!";
if ($branch->{status} !~ /stable/) {
print OUT '[[!template id=warning text="The '.$branch->{serie}.' serie is still in developpement."]]'."\n\n";
} elsif ($branch->{status} eq 'oldstable') {
print OUT '[[!template id=info text="The '.$branch->{serie}.' is not maintained anymore. You should consider an upgrade to the last stable release."]]'."\n\n";
}
print OUT $parser->as_markdown;
close OUT;
$wiki->run('add', $mdwnFile . '.mdwn');
$indexContent .= "* [[".$branch->{serie}." (".$branch->{status}.")|$mdwnFile]]\n";
}
}
}
open INDEX, ">documentation/references.mdwn" or die;
print INDEX $indexContent;
close INDEX;
$wiki->run('add', "documentation/references.mdwn");