annotate hgext/releasenotes.py @ 33900:6a49c74b1e8f

releasenotes: add check flag for use of admonitions and its validity While using releasenotes extension, we will be using admonitions in commit messages. The check (-c) flag will look for an admonition within the message. If it exists, it will verify if it is stated under default or custom admonition. The check fails if the admonition is not present in any of them. It also suggests similar admonitions in case the admonition is invalid. Differential Revision: https://phab.mercurial-scm.org/D368
author Rishabh Madan <rishabhmadan96@gmail.com>
date Sun, 13 Aug 2017 19:58:45 +0530
parents 589fda7895da
children 2a37459aedf2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1 # Copyright 2017-present Gregory Szorc <gregory.szorc@gmail.com>
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
2 #
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
3 # This software may be used and distributed according to the terms of the
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
4 # GNU General Public License version 2 or any later version.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
5
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
6 """generate release notes from commit messages (EXPERIMENTAL)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
7
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
8 It is common to maintain files detailing changes in a project between
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
9 releases. Maintaining these files can be difficult and time consuming.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
10 The :hg:`releasenotes` command provided by this extension makes the
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
11 process simpler by automating it.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
12 """
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
13
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
14 from __future__ import absolute_import
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
15
33900
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
16 import difflib
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
17 import errno
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
18 import re
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
19 import sys
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
20 import textwrap
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
21
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
22 from mercurial.i18n import _
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
23 from mercurial import (
33571
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
24 config,
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
25 error,
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
26 minirst,
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
27 registrar,
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
28 scmutil,
33571
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
29 util,
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
30 )
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
31
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
32 cmdtable = {}
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
33 command = registrar.command(cmdtable)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
34
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
35 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
36 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
37 # be specifying the version(s) of Mercurial they are tested with, or
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
38 # leave the attribute unspecified.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
39 testedwith = 'ships-with-hg-core'
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
40
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
41 DEFAULT_SECTIONS = [
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
42 ('feature', _('New Features')),
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
43 ('bc', _('Backwards Compatibility Changes')),
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
44 ('fix', _('Bug Fixes')),
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
45 ('perf', _('Performance Improvements')),
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
46 ('api', _('API Changes')),
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
47 ]
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
48
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
49 RE_DIRECTIVE = re.compile('^\.\. ([a-zA-Z0-9_]+)::\s*([^$]+)?$')
33724
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
50 RE_ISSUE = r'\bissue ?[0-9]{4,6}(?![0-9])\b'
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
51
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
52 BULLET_SECTION = _('Other Changes')
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
53
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
54 class parsedreleasenotes(object):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
55 def __init__(self):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
56 self.sections = {}
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
57
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
58 def __contains__(self, section):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
59 return section in self.sections
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
60
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
61 def __iter__(self):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
62 return iter(sorted(self.sections))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
63
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
64 def addtitleditem(self, section, title, paragraphs):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
65 """Add a titled release note entry."""
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
66 self.sections.setdefault(section, ([], []))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
67 self.sections[section][0].append((title, paragraphs))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
68
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
69 def addnontitleditem(self, section, paragraphs):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
70 """Adds a non-titled release note entry.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
71
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
72 Will be rendered as a bullet point.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
73 """
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
74 self.sections.setdefault(section, ([], []))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
75 self.sections[section][1].append(paragraphs)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
76
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
77 def titledforsection(self, section):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
78 """Returns titled entries in a section.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
79
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
80 Returns a list of (title, paragraphs) tuples describing sub-sections.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
81 """
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
82 return self.sections.get(section, ([], []))[0]
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
83
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
84 def nontitledforsection(self, section):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
85 """Returns non-titled, bulleted paragraphs in a section."""
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
86 return self.sections.get(section, ([], []))[1]
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
87
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
88 def hastitledinsection(self, section, title):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
89 return any(t[0] == title for t in self.titledforsection(section))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
90
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
91 def merge(self, ui, other):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
92 """Merge another instance into this one.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
93
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
94 This is used to combine multiple sources of release notes together.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
95 """
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
96 for section in other:
33724
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
97 existingnotes = converttitled(self.titledforsection(section)) + \
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
98 convertnontitled(self.nontitledforsection(section))
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
99 for title, paragraphs in other.titledforsection(section):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
100 if self.hastitledinsection(section, title):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
101 # TODO prompt for resolution if different and running in
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
102 # interactive mode.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
103 ui.write(_('%s already exists in %s section; ignoring\n') %
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
104 (title, section))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
105 continue
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
106
33724
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
107 incoming_str = converttitled([(title, paragraphs)])[0]
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
108 if section == 'fix':
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
109 issue = getissuenum(incoming_str)
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
110 if issue:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
111 if findissue(ui, existingnotes, issue):
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
112 continue
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
113
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
114 if similar(ui, existingnotes, incoming_str):
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
115 continue
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
116
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
117 self.addtitleditem(section, title, paragraphs)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
118
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
119 for paragraphs in other.nontitledforsection(section):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
120 if paragraphs in self.nontitledforsection(section):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
121 continue
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
122
33724
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
123 incoming_str = convertnontitled([paragraphs])[0]
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
124 if section == 'fix':
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
125 issue = getissuenum(incoming_str)
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
126 if issue:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
127 if findissue(ui, existingnotes, issue):
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
128 continue
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
129
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
130 if similar(ui, existingnotes, incoming_str):
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
131 continue
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
132
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
133 self.addnontitleditem(section, paragraphs)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
134
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
135 class releasenotessections(object):
33571
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
136 def __init__(self, ui, repo=None):
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
137 if repo:
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
138 sections = util.sortdict(DEFAULT_SECTIONS)
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
139 custom_sections = getcustomadmonitions(repo)
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
140 if custom_sections:
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
141 sections.update(custom_sections)
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
142 self._sections = list(sections.iteritems())
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
143 else:
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
144 self._sections = list(DEFAULT_SECTIONS)
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
145
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
146 def __iter__(self):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
147 return iter(self._sections)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
148
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
149 def names(self):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
150 return [t[0] for t in self._sections]
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
151
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
152 def sectionfromtitle(self, title):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
153 for name, value in self._sections:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
154 if value == title:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
155 return name
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
156
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
157 return None
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
158
33724
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
159 def converttitled(titledparagraphs):
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
160 """
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
161 Convert titled paragraphs to strings
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
162 """
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
163 string_list = []
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
164 for title, paragraphs in titledparagraphs:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
165 lines = []
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
166 for para in paragraphs:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
167 lines.extend(para)
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
168 string_list.append(' '.join(lines))
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
169 return string_list
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
170
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
171 def convertnontitled(nontitledparagraphs):
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
172 """
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
173 Convert non-titled bullets to strings
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
174 """
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
175 string_list = []
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
176 for paragraphs in nontitledparagraphs:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
177 lines = []
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
178 for para in paragraphs:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
179 lines.extend(para)
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
180 string_list.append(' '.join(lines))
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
181 return string_list
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
182
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
183 def getissuenum(incoming_str):
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
184 """
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
185 Returns issue number from the incoming string if it exists
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
186 """
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
187 issue = re.search(RE_ISSUE, incoming_str, re.IGNORECASE)
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
188 if issue:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
189 issue = issue.group()
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
190 return issue
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
191
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
192 def findissue(ui, existing, issue):
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
193 """
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
194 Returns true if issue number already exists in notes.
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
195 """
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
196 if any(issue in s for s in existing):
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
197 ui.write(_('"%s" already exists in notes; ignoring\n') % issue)
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
198 return True
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
199 else:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
200 return False
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
201
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
202 def similar(ui, existing, incoming_str):
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
203 """
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
204 Returns true if similar note found in existing notes.
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
205 """
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
206 if len(incoming_str.split()) > 10:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
207 merge = similaritycheck(incoming_str, existing)
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
208 if not merge:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
209 ui.write(_('"%s" already exists in notes file; ignoring\n')
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
210 % incoming_str)
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
211 return True
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
212 else:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
213 return False
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
214 else:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
215 return False
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
216
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
217 def similaritycheck(incoming_str, existingnotes):
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
218 """
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
219 Returns true when note fragment can be merged to existing notes.
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
220 """
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
221 import fuzzywuzzy.fuzz as fuzz
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
222 merge = True
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
223 for bullet in existingnotes:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
224 score = fuzz.token_set_ratio(incoming_str, bullet)
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
225 if score > 75:
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
226 merge = False
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
227 break
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
228 return merge
3748098d072a releasenotes: add similarity check function to compare incoming notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33571
diff changeset
229
33571
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
230 def getcustomadmonitions(repo):
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
231 ctx = repo['.']
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
232 p = config.config()
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
233
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
234 def read(f, sections=None, remap=None):
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
235 if f in ctx:
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
236 data = ctx[f].data()
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
237 p.parse(f, data, sections, remap, read)
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
238 else:
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
239 raise error.Abort(_(".hgreleasenotes file \'%s\' not found") %
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
240 repo.pathto(f))
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
241
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
242 if '.hgreleasenotes' in ctx:
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
243 read('.hgreleasenotes')
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
244 return p['sections']
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
245
33900
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
246 def checkadmonitions(ui, repo, directives, revs):
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
247 """
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
248 Checks the commit messages for admonitions and their validity.
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
249
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
250 .. abcd::
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
251
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
252 First paragraph under this admonition
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
253
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
254 For this commit message, using `hg releasenotes -r . --check`
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
255 returns: Invalid admonition 'abcd' present in changeset 3ea92981e103
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
256
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
257 As admonition 'abcd' is neither present in default nor custom admonitions
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
258 """
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
259 for rev in revs:
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
260 ctx = repo[rev]
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
261 admonition = re.search(RE_DIRECTIVE, ctx.description())
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
262 if admonition:
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
263 if admonition.group(1) in directives:
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
264 continue
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
265 else:
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
266 ui.write(_("Invalid admonition '%s' present in changeset %s"
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
267 "\n") % (admonition.group(1), ctx.hex()[:12]))
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
268 sim = lambda x: difflib.SequenceMatcher(None,
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
269 admonition.group(1), x).ratio()
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
270
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
271 similar = [s for s in directives if sim(s) > 0.6]
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
272 if len(similar) == 1:
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
273 ui.write(_("(did you mean %s?)\n") % similar[0])
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
274 elif similar:
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
275 ss = ", ".join(sorted(similar))
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
276 ui.write(_("(did you mean one of %s?)\n") % ss)
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
277
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
278 def parsenotesfromrevisions(repo, directives, revs):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
279 notes = parsedreleasenotes()
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
280
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
281 for rev in revs:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
282 ctx = repo[rev]
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
283
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
284 blocks, pruned = minirst.parse(ctx.description(),
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
285 admonitions=directives)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
286
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
287 for i, block in enumerate(blocks):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
288 if block['type'] != 'admonition':
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
289 continue
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
290
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
291 directive = block['admonitiontitle']
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
292 title = block['lines'][0].strip() if block['lines'] else None
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
293
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
294 if i + 1 == len(blocks):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
295 raise error.Abort(_('release notes directive %s lacks content')
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
296 % directive)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
297
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
298 # Now search ahead and find all paragraphs attached to this
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
299 # admonition.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
300 paragraphs = []
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
301 for j in range(i + 1, len(blocks)):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
302 pblock = blocks[j]
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
303
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
304 # Margin blocks may appear between paragraphs. Ignore them.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
305 if pblock['type'] == 'margin':
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
306 continue
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
307
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
308 if pblock['type'] != 'paragraph':
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
309 raise error.Abort(_('unexpected block in release notes '
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
310 'directive %s') % directive)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
311
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
312 if pblock['indent'] > 0:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
313 paragraphs.append(pblock['lines'])
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
314 else:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
315 break
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
316
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
317 # TODO consider using title as paragraph for more concise notes.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
318 if not paragraphs:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
319 raise error.Abort(_('could not find content for release note '
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
320 '%s') % directive)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
321
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
322 if title:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
323 notes.addtitleditem(directive, title, paragraphs)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
324 else:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
325 notes.addnontitleditem(directive, paragraphs)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
326
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
327 return notes
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
328
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
329 def parsereleasenotesfile(sections, text):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
330 """Parse text content containing generated release notes."""
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
331 notes = parsedreleasenotes()
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
332
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
333 blocks = minirst.parse(text)[0]
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
334
33028
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
335 def gatherparagraphsbullets(offset, title=False):
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
336 notefragment = []
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
337
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
338 for i in range(offset + 1, len(blocks)):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
339 block = blocks[i]
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
340
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
341 if block['type'] == 'margin':
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
342 continue
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
343 elif block['type'] == 'section':
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
344 break
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
345 elif block['type'] == 'bullet':
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
346 if block['indent'] != 0:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
347 raise error.Abort(_('indented bullet lists not supported'))
33028
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
348 if title:
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
349 lines = [l[1:].strip() for l in block['lines']]
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
350 notefragment.append(lines)
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
351 continue
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
352 else:
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
353 lines = [[l[1:].strip() for l in block['lines']]]
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
354
33028
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
355 for block in blocks[i + 1:]:
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
356 if block['type'] in ('bullet', 'section'):
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
357 break
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
358 if block['type'] == 'paragraph':
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
359 lines.append(block['lines'])
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
360 notefragment.append(lines)
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
361 continue
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
362 elif block['type'] != 'paragraph':
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
363 raise error.Abort(_('unexpected block type in release notes: '
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
364 '%s') % block['type'])
33028
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
365 if title:
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
366 notefragment.append(block['lines'])
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
367
33028
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
368 return notefragment
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
369
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
370 currentsection = None
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
371 for i, block in enumerate(blocks):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
372 if block['type'] != 'section':
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
373 continue
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
374
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
375 title = block['lines'][0]
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
376
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
377 # TODO the parsing around paragraphs and bullet points needs some
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
378 # work.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
379 if block['underline'] == '=': # main section
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
380 name = sections.sectionfromtitle(title)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
381 if not name:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
382 raise error.Abort(_('unknown release notes section: %s') %
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
383 title)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
384
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
385 currentsection = name
33028
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
386 bullet_points = gatherparagraphsbullets(i)
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
387 if bullet_points:
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
388 for para in bullet_points:
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
389 notes.addnontitleditem(currentsection, para)
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
390
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
391 elif block['underline'] == '-': # sub-section
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
392 if title == BULLET_SECTION:
33028
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
393 bullet_points = gatherparagraphsbullets(i)
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
394 for para in bullet_points:
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
395 notes.addnontitleditem(currentsection, para)
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
396 else:
33028
5814db57941c releasenotes: improve parsing around bullet points
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 32798
diff changeset
397 paragraphs = gatherparagraphsbullets(i, True)
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
398 notes.addtitleditem(currentsection, title, paragraphs)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
399 else:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
400 raise error.Abort(_('unsupported section type for %s') % title)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
401
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
402 return notes
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
403
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
404 def serializenotes(sections, notes):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
405 """Serialize release notes from parsed fragments and notes.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
406
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
407 This function essentially takes the output of ``parsenotesfromrevisions()``
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
408 and ``parserelnotesfile()`` and produces output combining the 2.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
409 """
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
410 lines = []
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
411
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
412 for sectionname, sectiontitle in sections:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
413 if sectionname not in notes:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
414 continue
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
415
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
416 lines.append(sectiontitle)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
417 lines.append('=' * len(sectiontitle))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
418 lines.append('')
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
419
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
420 # First pass to emit sub-sections.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
421 for title, paragraphs in notes.titledforsection(sectionname):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
422 lines.append(title)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
423 lines.append('-' * len(title))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
424 lines.append('')
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
425
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
426 wrapper = textwrap.TextWrapper(width=78)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
427 for i, para in enumerate(paragraphs):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
428 if i:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
429 lines.append('')
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
430 lines.extend(wrapper.wrap(' '.join(para)))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
431
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
432 lines.append('')
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
433
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
434 # Second pass to emit bullet list items.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
435
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
436 # If the section has titled and non-titled items, we can't
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
437 # simply emit the bullet list because it would appear to come
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
438 # from the last title/section. So, we emit a new sub-section
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
439 # for the non-titled items.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
440 nontitled = notes.nontitledforsection(sectionname)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
441 if notes.titledforsection(sectionname) and nontitled:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
442 # TODO make configurable.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
443 lines.append(BULLET_SECTION)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
444 lines.append('-' * len(BULLET_SECTION))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
445 lines.append('')
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
446
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
447 for paragraphs in nontitled:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
448 wrapper = textwrap.TextWrapper(initial_indent='* ',
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
449 subsequent_indent=' ',
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
450 width=78)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
451 lines.extend(wrapper.wrap(' '.join(paragraphs[0])))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
452
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
453 wrapper = textwrap.TextWrapper(initial_indent=' ',
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
454 subsequent_indent=' ',
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
455 width=78)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
456 for para in paragraphs[1:]:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
457 lines.append('')
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
458 lines.extend(wrapper.wrap(' '.join(para)))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
459
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
460 lines.append('')
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
461
33805
589fda7895da releasenotes: minor bug fix for index error while serializing
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33724
diff changeset
462 if lines and lines[-1]:
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
463 lines.append('')
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
464
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
465 return '\n'.join(lines)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
466
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
467 @command('releasenotes',
33900
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
468 [('r', 'rev', '', _('revisions to process for release notes'), _('REV')),
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
469 ('c', 'check', False, _('checks for validity of admonitions (if any)'),
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
470 _('REV'))],
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
471 _('hg releasenotes [-r REV] [-c] FILE'))
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
472 def releasenotes(ui, repo, file_=None, **opts):
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
473 """parse release notes from commit messages into an output file
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
474
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
475 Given an output file and set of revisions, this command will parse commit
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
476 messages for release notes then add them to the output file.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
477
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
478 Release notes are defined in commit messages as ReStructuredText
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
479 directives. These have the form::
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
480
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
481 .. directive:: title
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
482
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
483 content
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
484
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
485 Each ``directive`` maps to an output section in a generated release notes
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
486 file, which itself is ReStructuredText. For example, the ``.. feature::``
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
487 directive would map to a ``New Features`` section.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
488
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
489 Release note directives can be either short-form or long-form. In short-
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
490 form, ``title`` is omitted and the release note is rendered as a bullet
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
491 list. In long form, a sub-section with the title ``title`` is added to the
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
492 section.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
493
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
494 The ``FILE`` argument controls the output file to write gathered release
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
495 notes to. The format of the file is::
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
496
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
497 Section 1
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
498 =========
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
499
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
500 ...
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
501
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
502 Section 2
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
503 =========
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
504
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
505 ...
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
506
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
507 Only sections with defined release notes are emitted.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
508
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
509 If a section only has short-form notes, it will consist of bullet list::
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
510
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
511 Section
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
512 =======
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
513
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
514 * Release note 1
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
515 * Release note 2
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
516
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
517 If a section has long-form notes, sub-sections will be emitted::
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
518
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
519 Section
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
520 =======
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
521
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
522 Note 1 Title
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
523 ------------
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
524
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
525 Description of the first long-form note.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
526
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
527 Note 2 Title
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
528 ------------
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
529
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
530 Description of the second long-form note.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
531
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
532 If the ``FILE`` argument points to an existing file, that file will be
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
533 parsed for release notes having the format that would be generated by this
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
534 command. The notes from the processed commit messages will be *merged*
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
535 into this parsed set.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
536
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
537 During release notes merging:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
538
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
539 * Duplicate items are automatically ignored
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
540 * Items that are different are automatically ignored if the similarity is
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
541 greater than a threshold.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
542
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
543 This means that the release notes file can be updated independently from
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
544 this command and changes should not be lost when running this command on
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
545 that file. A particular use case for this is to tweak the wording of a
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
546 release note after it has been added to the release notes file.
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
547 """
33571
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
548 sections = releasenotessections(ui, repo)
33900
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
549 rev = opts.get('rev')
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
550
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
551 revs = scmutil.revrange(repo, [rev or 'not public()'])
33900
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
552 if opts.get('check'):
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
553 return checkadmonitions(ui, repo, sections.names(), revs)
6a49c74b1e8f releasenotes: add check flag for use of admonitions and its validity
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33805
diff changeset
554
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
555 incoming = parsenotesfromrevisions(repo, sections.names(), revs)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
556
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
557 try:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
558 with open(file_, 'rb') as fh:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
559 notes = parsereleasenotesfile(sections, fh.read())
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
560 except IOError as e:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
561 if e.errno != errno.ENOENT:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
562 raise
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
563
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
564 notes = parsedreleasenotes()
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
565
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
566 notes.merge(ui, incoming)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
567
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
568 with open(file_, 'wb') as fh:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
569 fh.write(serializenotes(sections, notes))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
570
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
571 @command('debugparsereleasenotes', norepo=True)
33571
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
572 def debugparsereleasenotes(ui, path, repo=None):
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
573 """parse release notes and print resulting data structure"""
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
574 if path == '-':
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
575 text = sys.stdin.read()
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
576 else:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
577 with open(path, 'rb') as fh:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
578 text = fh.read()
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
579
33571
9a944e908ecf releasenotes: add custom admonitions support for release notes
Rishabh Madan <rishabhmadan96@gmail.com>
parents: 33028
diff changeset
580 sections = releasenotessections(ui, repo)
32798
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
581
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
582 notes = parsereleasenotesfile(sections, text)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
583
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
584 for section in notes:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
585 ui.write(_('section: %s\n') % section)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
586 for title, paragraphs in notes.titledforsection(section):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
587 ui.write(_(' subsection: %s\n') % title)
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
588 for para in paragraphs:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
589 ui.write(_(' paragraph: %s\n') % ' '.join(para))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
590
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
591 for paragraphs in notes.nontitledforsection(section):
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
592 ui.write(_(' bullet point:\n'))
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
593 for para in paragraphs:
91e355a0408b releasenotes: command to manage release notes files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
594 ui.write(_(' paragraph: %s\n') % ' '.join(para))