^c W dZddlZddlZddlmZddlmZddlmZddl m Z m Z m Z m Z mZmZmZmZddlmZmZiZejeZ ddlZej5ejdd ed ddlmZejdddn #1swxYwYn #e$rdZYnwxYwd Zd edfdedfdedfdedfdedfgZ ej!dej"Z#dZ$edZ%GddZ&GddZ'dZ(dZ)d Z*d!Z+d"Z,d#Z-d$Z.d%Z/d&Z0d'Z1d(Z2d)Z3ed*d+d,d-ed.ed/fd0d1d2ed3ed/fd4d5d2ed6dfged7ej48d>d9Z5ed:d;<d>d=Z6dS)?a/generate release notes from commit messages (EXPERIMENTAL) It is common to maintain files detailing changes in a project between releases. Maintaining these files can be difficult and time consuming. The :hg:`releasenotes` command provided by this extension makes the process simpler by automating it. N)_)open)hex)cmdutilconfigerror logcmdutilminirstpycompat registrarutil)procutil stringutilignorez.*python-Levenshtein.*zfuzzywuzzy.fuzz)actionmessagecategorymodulesships-with-hg-coresfeatures New FeaturessbcsBackwards Compatibility Changesfixs Bug FixessperfsPerformance Improvementssapis API Changess#^\.\. ([a-zA-Z0-9_]+)::\s*([^$]+)?$s\bissue ?[0-9]{4,6}(?![0-9])\bs Other ChangescDeZdZdZdZdZdZdZdZdZ dZ d Z d S) parsedreleasenotesci|_dSNsectionsselfs 4/usr/lib/python3/dist-packages/hgext/releasenotes.py__init__zparsedreleasenotes.__init__Ps  c||jvSrrrsections r __contains__zparsedreleasenotes.__contains__Ss$-''r cDtt|jSr)itersortedrrs r__iter__zparsedreleasenotes.__iter__VsF4=))***r c|j|ggf|j|d||fdS)z Add a titled release note entry.rNr setdefaultappend)rr#title paragraphss r addtitleditemz parsedreleasenotes.addtitleditemYsI   2r(333 gq!((%)<=====r c|j|ggf|j|d|dS)z[Adds a non-titled release note entry. Will be rendered as a bullet point. Nr*)rr#r.s raddnontitleditemz#parsedreleasenotes.addnontitleditem^sF   2r(333 gq!((44444r cH|j|ggfdS)z|Returns titled entries in a section. Returns a list of (title, paragraphs) tuples describing sub-sections. rrgetr"s rtitledforsectionz#parsedreleasenotes.titledforsectionfs% }  2r(33A66r cH|j|ggfdS)z5Returns non-titled, bulleted paragraphs in a section.r1r4r"s rnontitledforsectionz&parsedreleasenotes.nontitledforsectionms#}  2r(33A66r c`tfd||DS)Nc30K|]}|dkVdS)rN).0tr-s r z8parsedreleasenotes.hastitledinsection..rs+IIQ1Q45=IIIIIIr )anyr6)rr#r-s `rhastitledinsectionz%parsedreleasenotes.hastitledinsectionqs4IIII$*?*?*H*HIIIIIIr cts"|td|D]}t||t ||z}||D]\}}|||r(|td||fzCt||fgd}|dkr#t|}|rt|||rt|||r| |||||D]}|||vrt |gd}|dkr#t|}|rt|||rYt|||rk| ||dS)z{Merge another instance into this one. This is used to combine multiple sources of release notes together. sKmodule 'fuzzywuzzy' not found, merging of similar releasenotes is disabled s*%s already exists in %s section; ignoring rrN)fuzzwarnr converttitledr6convertnontitledr8r@write getissuenum findissuesimilarr/r2) ruiotherr# existingnotesr-r. incoming_strissues rmergezparsedreleasenotes.mergets<   GG2   ( ;( ;G)%%g.. !9!9'!B!BCCDM&+%;%;G%D%D ? ?!z**7E::HHHII '*+,uj.A-BCCAF f$$' 55E%$R>>%$2}l;;""7E:>>>>#77@@ ; ; !9!9'!B!BBB/ ==a@ f$$' 55E%$R>>%$2}l;;%%gz:::: ;5( ;( ;r N) __name__ __module__ __qualname__rr$r(r/r2r6r8r@rOr;r rrrOs(((+++>>> 555777777JJJ5;5;5;5;5;r rc(eZdZddZdZdZdZdS)releasenotessectionsNc |rgtjt}t|}|r||t ||_dSt t|_dSr)r sortdictDEFAULT_SECTIONSgetcustomadmonitionsupdatelistitems _sections)rrJreporcustom_sectionss rrzreleasenotessections.__init__sr  4}%566H2488O 1000!(.."2"233DNNN!"233DNNNr c*t|jSr)r&r\rs rr(zreleasenotessections.__iter__sDN###r c$d|jDS)Ncg|] }|d S)rr;)r<r=s r z.releasenotessections.names..s---!---r r\rs rnameszreleasenotessections.namess--dn----r c4|jD]\}}||kr|cSdSrrc)rr-namevalues rsectionfromtitlez%releasenotessections.sectionfromtitles5>  KD%~~ tr r)rPrQrRrr(rdrhr;r rrTrTsU4444$$$...r rTcg}|D]I\}}g}|D]}|||d|J|S)z. Convert titled paragraphs to strings  extendr,join)titledparagraphs string_listr-r.linesparas rrDrDsoK---z  D LL    499U++,,,, r cg}|D]F}g}|D]}|||d|G|S)z/ Convert non-titled bullets to strings rjrk)nontitledparagraphsror.rprqs rrErEsjK)--   D LL    499U++,,,, r c|tjt|tj}|r|}|S)zD Returns issue number from the incoming string if it exists )researchRE_ISSUE IGNORECASEgroup)rMrNs rrGrGs3 Ih bm < zfindissue..s' ( (!5A: ( ( ( ( ( (r s'"%s" already exists in notes; ignoring TF)r?rFr)rJexistingrNs `rrHrHsT ( ( ( (x ( ( ((( >??%GHHHtur ct|dkr;t||}|s'|t d|zdSdSdS)z? Returns true if similar note found in existing notes. s,"%s" already exists in notes file; ignoring TF)lensplitsimilaritycheckrFr)rJr}rMrOs rrIrIsu <      2%% h77  HHBCC   45ur cdtsdSd}|D]!}tj||}|dkrd}n"|S)zK Returns false when note fragment can be merged to existing notes. TKF)rBtoken_set_ratio)rMrLrObulletscores rrrsV t E$\6:: 2::E E  Lr cdtjdfd dvr ddS)N.c|vr5|}||||dStjt d|z)Ns#.hgreleasenotes file '%s' not found)dataparserAbortrpathto)frremaprctxpreadr]s rrz"getcustomadmonitions..readsl 88q6;;==D GGAtXud 3 3 3 3 3+:;;dkk!nnL r s.hgreleasenotesssections)NN)rr[)r]rrrs`@@@rrXrXsw t*C AS       77;  r c |D]A}||}tjt|rd|vrR|t dd|ddfzfd fd|D}t|dkr,|t d|dz|rGd t|}|t d |zCdS) a` Checks the commit messages for admonitions and their validity. .. abcd:: First paragraph under this admonition For this commit message, using `hg releasenotes -r . --check` returns: Invalid admonition 'abcd' present in changeset 3ea92981e103 As admonition 'abcd' is neither present in default nor custom admonitions r1s0Invalid admonition '%s' present in changeset %s N cztjdd|S)Nr1)difflibSequenceMatcherryratio)x admonitions rz"checkadmonitions..As5 7***1--q!!%''r c2g|]}|dk|S)g333333?r;)r<r|sims rrbz$checkadmonitions..Es&AAACCFFSLL1LLLr s(did you mean %s?) rs, s(did you mean one of %s?) ) rurv RE_DIRECTIVE descriptionryrFrrrrmr') rJr] directivesrevsrevrrIssrrs @@rcheckadmonitionsr)sdEE3iY|S__->->??  E""j00JKK!''**CGGIIcrcN;<BAAAjAAAw<<1$$HHQ677'!*DEEEEEF7OO44BHHQ=>>CDDD)EEr c\|D](}|d|d|dfz)dS)Ns%s: %s rr1)rF)rJrr#s r_getadmonitionlistrMsB99  GAJ77888899r c t}|D]}||}tj||\}}t |D]\}} | ddkr| d} | dr | ddnd} |dzt |kr&tjtd|| fzg} t|dzt |D]} || }|dd kr|ddkrna|dd kr,|j td || fz|d dkr| |d| sI|j td t|z| r|| | | || | |S)N) admonitionstypes admonitionsadmonitiontitlelinesrr1s6changeset %s: release notes directive %s lacks contentmargin paragraphs=changeset %s: unexpected block in release notes directive %s indents.error parsing releasenotes for revision: '%s' )rr rr enumeratestriprrrrrangerJrCr,rnoder/r2)r]rrnotesrrblocksprunediblock directiver-r.jpblocks rparsenotesfromrevisionsrRs^  E;>;>3i  OO  :   "&))4 >4 >HAuW~..01I27/KE(OA&,,...tE1uF ##k)I& 'J1q5#f++..  '?i//'?m33E'?l22GLL4 * +)$q((%%fX&67777  HII#((**oo& >##IujAAAA&&y*====i4 >l Lr c t}tj|d d fd }d}t D]\}}|ddkr|dd}|dd krf||}|s$t jtd |z|}||} | r| D]} ||| |dd krV|tkr'||} | D]} ||| ||d } | ||| t jtd |z|S)z6Parse text content containing generated release notes.rFcg}t|dztD]I}|}|ddkr|ddkrn$|ddkr|ddkr!tjt d|r(d |d D}||d |d Dg}|dzdD]5}|dd vrn(|dd kr||d 6|||dd kr*tjt d|dz|r||d K|S)Nr1rrsectionbulletrrs#indented bullet lists not supportedcFg|]}|ddSr1Nrr<ls rrbzJparsereleasenotesfile..gatherparagraphsbullets..s(DDDqQqrrU[[]]DDDr rcFg|]}|ddSrrrs rrbzJparsereleasenotesfile..gatherparagraphsbullets..s(EEEaekkmmEEEr )rrrs*unexpected block type in release notes: %s)rrrrrr,)offsetr- notefragmentrrrprs rgatherparagraphsbulletsz6parsereleasenotesfile..gatherparagraphsbulletss vz3v;;// 5 5A1IEW~**w:--w9,,#q((+a(N&O&OPPP DDE(ODDDE ''...EEU8_EEEFE!'A:: >-DDD!E >\99!LLx999 ''...w<//kCDDGn% 5##E(O444r Nrrrs underline=s!unknown release notes section: %s-Tsunsupported section type for %s)F) rr rrrhrrrr2BULLET_SECTIONr/) rtextrrcurrentsectionrrr-rf bullet_pointsrqr.rs @rparsereleasenotesfilers  E ]4  #F######JNf%%MM5 >Z ' ' h"  $ & &,,U33D k:;;eC"N33A66M A)AAD**>4@@@@ < D ( (&& 7 7 : : )AAD**>4@@@@A54Q== ##NE:FFFF+a BCCeKLL L Lr c g}|D]\}}||vr |||dt|z|d||D]\}}|||dt|z|dt|D]j\}}|r|d|t jd|dk|d| |} ||r[| rY|t|dttz|d| D]}|t jd|dddd |d d D]g}|d|t jd|dd d h|d|r|d r|dd|S)zSerialize release notes from parsed fragments and notes. This function essentially takes the output of ``parsenotesfromrevisions()`` and ``parserelnotesfile()`` and produces output combining the 2. rr rrjN)widthrs* s )r initindent hangindentr1N ) r,rr6rrlrwraprm splitlinesr8r) rrrp sectionname sectiontitler-r.rrq nontitleds rserializenotesrs E%-99! \ e # #  \""" TC ---... S"'!7!7 !D!D   E: LL    LLE * + + + LL   $Z00  4&LL%%% ODIIdOO2>>>IIKK LL    --k::  ! !+ . . 9  LL ( ( ( LLN 3 33 4 4 4 LL   #  J LLIIjm,,$$  *,,    #122   S!!! O $ #(#(  !jll  LL    + . r S ::e  r releasenotesrrevr s&revisions to process for release notessREVccheckFs+checks for validity of admonitions (if any)llists/list the available admonitions with their titles"hg releasenotes [-r REV] [-c] FILE) helpcategoryc tj|}t||}tj|dddg|drt ||S|d}tj||pdg}|dr$t||| |St|| |}|8| d| t||S t|d5}t!||} dddn #1swxYwYn#t$$rt'} YnwxYw| ||t|d5}| t|| ddddS#1swxYwYdS) a parse release notes from commit messages into an output file Given an output file and set of revisions, this command will parse commit messages for release notes then add them to the output file. Release notes are defined in commit messages as ReStructuredText directives. These have the form:: .. directive:: title content Each ``directive`` maps to an output section in a generated release notes file, which itself is ReStructuredText. For example, the ``.. feature::`` directive would map to a ``New Features`` section. Release note directives can be either short-form or long-form. In short- form, ``title`` is omitted and the release note is rendered as a bullet list. In long form, a sub-section with the title ``title`` is added to the section. The ``FILE`` argument controls the output file to write gathered release notes to. The format of the file is:: Section 1 ========= ... Section 2 ========= ... Only sections with defined release notes are emitted. If a section only has short-form notes, it will consist of bullet list:: Section ======= * Release note 1 * Release note 2 If a section has long-form notes, sub-sections will be emitted:: Section ======= Note 1 Title ------------ Description of the first long-form note. Note 2 Title ------------ Description of the second long-form note. If the ``FILE`` argument points to an existing file, that file will be parsed for release notes having the format that would be generated by this command. The notes from the processed commit messages will be *merged* into this parsed set. During release notes merging: * Duplicate items are automatically ignored * Items that are different are automatically ignored if the similarity is greater than a threshold. This means that the release notes file can be updated independently from this command and changes should not be lost when running this command on that file. A particular use case for this is to tweak the wording of a release note after it has been added to the release notes file. The -c/--check option checks the commit message for invalid admonitions. The -l/--list option, presents the user with a list of existing available admonitions along with their title. This also includes the custom admonitions (if any). rrrs not public()Nrrbswb)r byteskwargsrTrcheck_incompatible_argumentsr5rr revrangerrdrpagerrFrrrrFileNotFoundErrorrrO) rJr]file_optsrrrincomingfhrs r releasenotesr-sZ^   % %D#B--H (w8JKKK xx0!"h/// ((6  C  tc&<_%= > >D xxBD(..*:*:DAAA&tX^^-=-=tDDH } !!!xxx::;;;% %   ?2)(BGGII>>E ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? %%%"$$% KKH eU  2r %00111222222222222222222sH&E16#E% E1%E))E1,E)-E11F  F 5$G&&G*-G*sdebugparsereleasenotesT)norepoc H|dkrtj}nrs  ######                      ) H % %OOO  " "  , $      '&&&&&                 DDD# ?##$ AA0 1 12 QQ|__ aa+,,- QQ~   rzA2<PP -#$$Z;Z;Z;Z;Z;Z;Z;Z;z2      $"   $!E!E!EH999 @@@FLLL^FFFR     A7 8 8 AfII      A< = = AfII      A@ A A   .A+,,358o2o2o298o2d  "4000FFF10FFFs6 B"B  B BBBBB#"B#