Rfaulk has submitted this change and it was merged.

Change subject: add - logic to revert handling extraction of latest tag.
......................................................................


add - logic to revert handling extraction of latest tag.

Change-Id: I13bb48b9e2a6d838fad3b8eb3f7520a8a939876b
---
M sartoris/config.py
M sartoris/git-deploy
M sartoris/sartoris.py
3 files changed, 18 insertions(+), 2 deletions(-)

Approvals:
  Rfaulk: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/sartoris/config.py b/sartoris/config.py
index b090456..c99580f 100644
--- a/sartoris/config.py
+++ b/sartoris/config.py
@@ -36,6 +36,7 @@
     10: 'Please specify number of deploy tags to emit with -c.  Exiting',
     11: 'Could not find any deploys.  Exiting',
     12: 'Tagging failed. Exiting',
+    13: 'Revert tag not found. Exiting',
     19: 'Missing system configuration item "deploy.client-path". Exiting.',
     20: 'Cannot find top level directory for the git repository. Exiting.',
     21: 'Missing system configuration item "hook-dir". Exiting.',
diff --git a/sartoris/git-deploy b/sartoris/git-deploy
index 7e335c6..836f587 100755
--- a/sartoris/git-deploy
+++ b/sartoris/git-deploy
@@ -57,6 +57,9 @@
     parser.add_argument("-f", "--force",
                         action="store_true",
                         help="force the action, bypass sanity checks.")
+    parser.add_argument("-t", "--tag",
+                        default='', type =str,
+                        help="Specify the tag for the revert action.")
 
     args = parser.parse_args()
     return args
diff --git a/sartoris/sartoris.py b/sartoris/sartoris.py
index 26a5093..53b9b2f 100755
--- a/sartoris/sartoris.py
+++ b/sartoris/sartoris.py
@@ -55,6 +55,9 @@
 
 class Sartoris(object):
 
+    # Pattern for git-deploy tags
+    TAG_PATTERN = r'[a-zA-Z]*-[0-9]{8}-[0-9]{6}'
+
     # Module level attribute for tagging datetime format
     DATE_TIME_TAG_FORMAT = '%Y%m%d-%H%M%S'
 
@@ -413,22 +416,31 @@
     def revert(self, args):
         """
             * write a lock file
+            * reset to last or specified tag
             * call sync hook with the prefix (repo) and tag info
         """
 
-        #TODO: do git calls in dulwich, rather than shelling out
         if not self._check_lock():
             raise SartorisError(message=exit_codes[30])
 
         revert_tag = self._make_tag()
 
         # Extract tag on which to revert
+        tag = ''
         if hasattr(args, 'tag'):
             tag = args.tag
         else:
             # revert to last tag
-            raise NotImplementedError()
+            for item in os.walk(self.config['top_dir'] + '/.git/refs/tags/'):
+                if search(r'/.git/refs/tags/', item[0]):
+                    tag = item[2][-1]
+                    break
 
+        # Ensure tag to revert to was set
+        if tag == '':
+            raise SartorisError(message=exit_codes[13], exit_code=13)
+
+        # TODO - use dulwich
         reset_cmd = 'git reset {0}'.format(tag)
         add_cmd = 'git add *'
         commit_cmd = 'git commit -m "revert to \'{0}\'"'.format(tag)

-- 
To view, visit https://gerrit.wikimedia.org/r/86362
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I13bb48b9e2a6d838fad3b8eb3f7520a8a939876b
Gerrit-PatchSet: 1
Gerrit-Project: sartoris
Gerrit-Branch: master
Gerrit-Owner: Rfaulk <[email protected]>
Gerrit-Reviewer: Rfaulk <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to