77
88import debug
99
10+ from collections import OrderedDict
11+
1012from django .db import migrations
1113
1214"""
4143 "GitLab User Name" : "gitlab_username" ,
4244}
4345
46+ # TODO: Review all the None values below and make sure ignoring the URLs they match is really the right thing to do.
47+ url_map = OrderedDict ({
48+ "https?://github\\ .com" : "github_repo" ,
49+ "https?://trac\\ .ietf\\ .org/.*/wiki" : "wiki" ,
50+ "ietf\\ .org.*/trac/wiki" : "wiki" ,
51+ "trac.*wiki" : "wiki" ,
52+ "www\\ .ietf\\ .org/mailman" : None ,
53+ "www\\ .ietf\\ .org/mail-archive" : None ,
54+ "mailarchive\\ .ietf\\ .org" : None ,
55+ "ietf\\ .org/logs" : "jabber_log" ,
56+ "ietf\\ .org/jabber/logs" : "jabber_log" ,
57+ "xmpp:.*?join" : "jabber_room" ,
58+ "bell-labs\\ .com" : None ,
59+ "html\\ .charters" : None ,
60+ "datatracker\\ .ietf\\ .org" : None ,
61+ })
62+
4463def forward (apps , schema_editor ):
4564 DocExtResource = apps .get_model ('doc' , 'DocExtResource' )
46- ExtResource = apps .get_model ('extresource' , 'ExtResource' )
4765 ExtResourceName = apps .get_model ('name' , 'ExtResourceName' )
4866 DocumentUrl = apps .get_model ('doc' , 'DocumentUrl' )
4967
5068 mapped = 0
5169 not_mapped = 0
70+ ignored = 0
5271
5372 for doc_url in DocumentUrl .objects .all ():
5473 match_found = False
@@ -57,13 +76,31 @@ def forward(apps, schema_editor):
5776 match_found = True
5877 mapped += 1
5978 name = ExtResourceName .objects .get (slug = slug )
60- ext_res = ExtResource .objects .create (name_id = slug , value = doc_url .url ) # TODO: validate this value against name.type
61- DocExtResource .objects .create (doc = doc_url .doc , extresource = ext_res )
79+ DocExtResource .objects .create (doc = doc_url .doc , name_id = slug , value = doc_url .url ) # TODO: validate this value against name.type
6280 break
81+ if not match_found :
82+ for regext , slug in url_map .items ():
83+ if re .search (regext , doc_url .url ):
84+ match_found = True
85+ if slug :
86+ mapped += 1
87+ name = ExtResourceName .objects .get (slug = slug )
88+ # Munge the URL if it's the first github repo match
89+ # Remove "/tree/master" substring if it exists
90+ # Remove trailing "/issues" substring if it exists
91+ # Remove "/blob/master/.*" pattern if present
92+ if regext == "https?://github\\ .com" :
93+ doc_url .url = doc_url .url .replace ("/tree/master" ,"" )
94+ doc_url .url = re .sub ('/issues$' , '' , doc_url .url )
95+ doc_url .url = re .sub ('/blob/master.*$' , '' , doc_url .url )
96+ DocExtResource .objects .create (doc = doc_url .doc , name_id = slug , value = doc_url .url ) # TODO: validate this value against name.type
97+ else :
98+ ignored += 1
99+ break
63100 if not match_found :
64101 debug .show ('("Not Mapped:",doc_url.desc, doc_url.tag.slug, doc_url.doc.name, doc_url.url)' )
65102 not_mapped += 1
66- debug .show ('(mapped, not_mapped)' )
103+ debug .show ('(mapped, ignored, not_mapped)' )
67104
68105def reverse (apps , schema_editor ):
69106 DocExtResource = apps .get_model ('doc' , 'DocExtResource' )
@@ -73,7 +110,6 @@ class Migration(migrations.Migration):
73110
74111 dependencies = [
75112 ('doc' , '0032_extres' ),
76- ('extresource' , '0001_extres' ),
77113 ('name' , '0011_populate_extres' ),
78114 ]
79115
0 commit comments