public void Run(UntappdSharp.Untappd U, string[] tokens)
 {
     if(tokens.Length >= 2)
     {
         try {
             int beerId = Int32.Parse(tokens[1]);
             CheckinOptions opt = new CheckinOptions();
             opt.BeerId = beerId;
             opt.Timezone = TimeZoneInfo.Local;
             UtCheckin chk = U.CheckinTest(opt);
             Console.WriteLine(string.Format(@"Checkin #{0}: {1}
     Beer #{2}: {3}
     Total checkins for this beer: {4}
     Total checkins for this beer this month: {5}
     Checked in at: {6} in {7}, {8}",
                 chk.CheckinDetails.CheckinId, chk.CheckinDetails.Shout,
                 chk.BeerDetails.BeerId, chk.BeerDetails.BeerName,
                 chk.CheckinTotal.Beer, chk.CheckinTotal.BeerMonth,
                 chk.FoursquareDetails.Name, chk.FoursquareDetails.City, chk.FoursquareDetails.State));
         } catch(UntappdApiException ex) {
             UtConsole.Err("Untappd API exception:");
             UtConsole.Err(ex.Message);
             UtConsole.Err(ex.InnerException.Message);
             UtConsole.Err(ex.InnerException.StackTrace);
         } catch(Exception ex) {
             UtConsole.Err("General exception:");
             UtConsole.Err(ex.Message);
             UtConsole.Err(ex.StackTrace);
         }
     } else {
         UtConsole.Err("Expected one argument: <beerid> (integer)");
     }
 }
Beispiel #2
0
 public void Shelve(string shelvesetName, string head, TfsChangesetInfo parentChangeset, CheckinOptions options, bool evaluateCheckinPolicies)
 {
     WithWorkspace(parentChangeset, workspace => Shelve(shelvesetName, head, parentChangeset, options, evaluateCheckinPolicies, workspace));
 }
 public int Checkin(string head, string parent, TfsChangesetInfo parentChangeset, CheckinOptions options, string sourceTfsPath = null)
 {
     throw DerivedRemoteException;
 }
Beispiel #4
0
        public int Checkin(CheckinOptions options, Func <string> generateCheckinComment = null)
        {
            if (options == null)
            {
                options = _checkinOptions;
            }

            var checkinComment = options.CheckinComment;

            if (string.IsNullOrWhiteSpace(checkinComment) && !options.NoGenerateCheckinComment && generateCheckinComment != null)
            {
                checkinComment = generateCheckinComment();
            }

            var pendingChanges = _workspace.GetPendingChanges();

            if (pendingChanges.IsEmpty())
            {
                throw new GitTfsException("Nothing to checkin!");
            }

            var workItemInfos = GetWorkItemInfos(options);
            var checkinNote   = _tfsHelper.CreateCheckinNote(options.CheckinNotes);

            var checkinProblems = _policyEvaluator.EvaluateCheckin(_workspace, pendingChanges, checkinComment, checkinNote, workItemInfos);

            if (checkinProblems.HasErrors)
            {
                foreach (var message in checkinProblems.Messages)
                {
                    if (options.Force && string.IsNullOrWhiteSpace(options.OverrideReason) == false)
                    {
                        Trace.TraceWarning("[OVERRIDDEN] " + message);
                    }
                    else
                    {
                        Trace.TraceError("[ERROR] " + message);

                        Trace.TraceInformation("Note: If the checkin policy fails because the assemblies failed to load, please run the file `enable_checkin_policies_support.bat` in the git-tfs directory and try again.");
                    }
                }
                if (!options.Force)
                {
                    throw new GitTfsException("No changes checked in.");
                }
                if (string.IsNullOrWhiteSpace(options.OverrideReason))
                {
                    throw new GitTfsException("A reason must be supplied (-f REASON) to override the policy violations.");
                }
            }

            var policyOverride = GetPolicyOverrides(options, checkinProblems.Result);

            try
            {
                var newChangeset = _workspace.Checkin(pendingChanges, checkinComment, options.AuthorTfsUserId, checkinNote, workItemInfos, policyOverride, options.OverrideGatedCheckIn);
                if (newChangeset == 0)
                {
                    throw new GitTfsException("Checkin failed!");
                }
                else
                {
                    return(newChangeset);
                }
            }
            catch (GitTfsGatedCheckinException e)
            {
                return(LaunchGatedCheckinBuild(e.AffectedBuildDefinitions, e.ShelvesetName, e.CheckInTicket));
            }
        }
Beispiel #5
0
        private IEnumerable <T> GetWorkItemInfosHelper <T>(Func <IEnumerable <string>, TfsWorkItemCheckinAction, IEnumerable <T> > func, CheckinOptions options = null)
        {
            var checkinOptions = options ?? _checkinOptions;

            var workItemInfos = func(checkinOptions.WorkItemsToAssociate, TfsWorkItemCheckinAction.Associate);

            workItemInfos = workItemInfos.Append(
                func(checkinOptions.WorkItemsToResolve, TfsWorkItemCheckinAction.Resolve));
            return(workItemInfos);
        }
Beispiel #6
0
 public TfsWorkspace(IWorkspace workspace, string localDirectory, TextWriter stdout, TfsChangesetInfo contextVersion, IGitTfsRemote remote, CheckinOptions checkinOptions, ITfsHelper tfsHelper, CheckinPolicyEvaluator policyEvaluator)
 {
     _workspace       = workspace;
     _policyEvaluator = policyEvaluator;
     _contextVersion  = contextVersion;
     _remote          = remote;
     _checkinOptions  = checkinOptions;
     _tfsHelper       = tfsHelper;
     _localDirectory  = localDirectory;
     _stdout          = stdout;
 }
Beispiel #7
0
 public UtCheckin Checkin(CheckinOptions Options)
 {
     return CheckinInternal(Options, true);
 }
Beispiel #8
0
        public TfsWorkspace(IWorkspace workspace, string localDirectory, TfsChangesetInfo contextVersion, IGitTfsRemote remote, CheckinOptions checkinOptions, ITfsHelper tfsHelper, CheckinPolicyEvaluator policyEvaluator)
        {
            _workspace       = workspace;
            _policyEvaluator = policyEvaluator;
            _contextVersion  = contextVersion;
            _checkinOptions  = checkinOptions;
            _tfsHelper       = tfsHelper;
            _localDirectory  = remote.Repository.IsBare ? Path.GetFullPath(localDirectory) : localDirectory;

            Remote = remote;
        }
Beispiel #9
0
 public long Checkin(string treeish, TfsChangesetInfo parentChangeset, CheckinOptions options, string sourceTfsPath = null)
 {
     throw DerivedRemoteException;
 }
Beispiel #10
0
        public int Checkin(CheckinOptions options)
        {
            if (options == null)
            {
                options = _checkinOptions;
            }

            var pendingChanges = _workspace.GetPendingChanges();

            if (pendingChanges.IsEmpty())
            {
                throw new GitTfsException("Nothing to checkin!");
            }

            var workItemInfos = GetWorkItemInfos(options);
            var checkinNote   = _tfsHelper.CreateCheckinNote(options.CheckinNotes);

            var checkinProblems = _policyEvaluator.EvaluateCheckin(_workspace, pendingChanges, options.CheckinComment, checkinNote, workItemInfos);

            if (checkinProblems.HasErrors)
            {
                foreach (var message in checkinProblems.Messages)
                {
                    if (options.Force && string.IsNullOrWhiteSpace(options.OverrideReason) == false)
                    {
                        _stdout.WriteLine("[OVERRIDDEN] " + message);
                    }
                    else
                    {
                        _stdout.WriteLine("[ERROR] " + message);
                    }
                }
                if (!options.Force)
                {
                    throw new GitTfsException("No changes checked in.");
                }
                if (String.IsNullOrWhiteSpace(options.OverrideReason))
                {
                    throw new GitTfsException("A reason must be supplied (-f REASON) to override the policy violations.");
                }
            }

            var policyOverride = GetPolicyOverrides(options, checkinProblems.Result);

            try
            {
                var newChangeset = _workspace.Checkin(pendingChanges, options.CheckinComment, options.AuthorTfsUserId, checkinNote, workItemInfos, policyOverride, options.OverrideGatedCheckIn);
                if (newChangeset == 0)
                {
                    throw new GitTfsException("Checkin failed!");
                }
                else
                {
                    return(newChangeset);
                }
            }
            catch (GitTfsGatedCheckinException e)
            {
                return(LaunchGatedCheckinBuild(e.AffectedBuildDefinitions, e.ShelvesetName, e.CheckInTicket));
            }
        }
Beispiel #11
0
 private long Checkin(string head, string parent, ITfsWorkspace workspace, CheckinOptions options)
 {
     PendChangesToWorkspace(head, parent, workspace);
     return(workspace.Checkin(options));
 }
Beispiel #12
0
        public long Checkin(string head, string parent, TfsChangesetInfo parentChangeset, CheckinOptions options)
        {
            var changeset = 0L;

            WithWorkspace(parentChangeset, workspace => changeset = Checkin(head, parent, workspace, options));
            return(changeset);
        }
Beispiel #13
0
 public long Checkin(string treeish, TfsChangesetInfo parentChangeset, CheckinOptions options)
 {
     throw new NotImplementedException();
 }
Beispiel #14
0
        private UtCheckin CheckinInternal(CheckinOptions Options, bool IsRealCheckin)
        {
            // CheckinOptions allow for CheckinTest:
            // gmt_offset    : required
            // bid           : required, beer ID
            // foursquare_id : optional
            // user_lat      : optional, but required if location given
            // user_lng      : optional, but required if location given

            try
            {
                dynamic args = new JsonObject();
                args.gmt_offset = GetGmtOffset(Options.Timezone);
                args.bid = Options.BeerId;
                args.foursquare_id = Options.FoursquareId;
                args.user_lat = Options.UserLat;
                args.user_lng = Options.UserLng;

                dynamic response;
                if(IsRealCheckin)
                {
                    response = _Client.checkin(args);
                } else {
                    response = _Client.checkin_test(args);
                }
                if(null != response.Result)
                {
                    return UtCheckin.FromDynamic(response.Result);
                }

                return null;
            } catch(Exception ex) {
                throw new UntappdApiException(ex);
            }
        }
Beispiel #15
0
 public UtCheckin CheckinTest(CheckinOptions Options)
 {
     return CheckinInternal(Options, false);
 }
Beispiel #16
0
 private void Shelve(string shelvesetName, string head, TfsChangesetInfo parentChangeset, CheckinOptions options, bool evaluateCheckinPolicies, ITfsWorkspace workspace)
 {
     PendChangesToWorkspace(head, parentChangeset.GitCommit, workspace);
     workspace.Shelve(shelvesetName, evaluateCheckinPolicies, options, () => Repository.GetCommitMessage(head, parentChangeset.GitCommit));
 }
Beispiel #17
0
        public int Checkin(string head, string parent, TfsChangesetInfo parentChangeset, CheckinOptions options, string sourceTfsPath = null)
        {
            var changeset = 0;

            WithWorkspace(parentChangeset, workspace => changeset = Checkin(head, parent, workspace, options, sourceTfsPath));
            return(changeset);
        }
 public void Shelve(string shelvesetName, string treeish, TfsChangesetInfo parentChangeset, CheckinOptions options, bool evaluateCheckinPolicies)
 {
     throw DerivedRemoteException;
 }
Beispiel #19
0
 private IEnumerable <IWorkItemCheckinInfo> GetWorkItemInfos(CheckinOptions options = null)
 {
     return(GetWorkItemInfosHelper <IWorkItemCheckinInfo>(_tfsHelper.GetWorkItemInfos, options));
 }
 public long Checkin(string head, string parent, TfsChangesetInfo parentChangeset, CheckinOptions options, string sourceTfsPath = null)
 {
     throw new NotImplementedException();
 }