public static bool TryParse( string repoFullName, string refSpec, string fullPath, Commit commit, out ModifiedFileModel model) { // the file path goes like the following: // https://github.com/<owner>/<repo>/blob/<branch>/<fullPath> // NOTE: only supports github files for now. model = null; if (!refSpec.StartsWith("refs/heads/")) { Trace.TraceError($"Invalid RefSpec - expecting to start with 'refs/heads/': '{refSpec}'"); return(false); } string branchName = refSpec.Substring("refs/heads/".Length); model = new ModifiedFileModel() { RepoName = repoFullName, BranchName = branchName, FullPath = "https://github.com/" + string.Join("/", repoFullName, "blob", branchName, fullPath), CommitId = commit.id }; return(true); }
public IEnumerable <ISubscriptionHandler> GetHandlers(ModifiedFileModel modifiedFile) { List <ISubscriptionHandler> subscriptionHandlers = new List <ISubscriptionHandler>(); HandlerResolver resolver = new HandlerResolver(this); foreach (Subscription subscription in GetSubscriptions(modifiedFile)) { try { var parameterSubstitutions = new Dictionary <string, string> { { "<trigger-repo>", modifiedFile.RepoName }, { "<trigger-branch>", modifiedFile.BranchName }, { "<trigger-path>", modifiedFile.FullPath }, { "<trigger-commit>", modifiedFile.CommitId } }; ISubscriptionHandler subscriptionHandler = resolver.Resolve(subscription, parameterSubstitutions); subscriptionHandlers.Add(subscriptionHandler); } catch (Exception e) { Trace.TraceError(e.Message); } } return(subscriptionHandlers); }
private bool Matches(string path, ModifiedFileModel modifiedFile) { bool matches = string.Equals(path, modifiedFile.FullPath, StringComparison.OrdinalIgnoreCase); if (matches) { return(true); } if (path.EndsWith("/**/*", StringComparison.OrdinalIgnoreCase)) { string rootPath = path.Substring(0, path.Length - 5); return(modifiedFile.FullPath.StartsWith(rootPath, StringComparison.OrdinalIgnoreCase)); } return(false); }
public IEnumerable <ISubscriptionHandler> GetHandlers(ModifiedFileModel modifiedFile) { List <ISubscriptionHandler> subscriptionHandlers = new List <ISubscriptionHandler>(); HandlerResolver resolver = new HandlerResolver(this); foreach (Subscription subscription in GetSubscriptions(modifiedFile)) { try { ISubscriptionHandler subscriptionHandler = resolver.Resolve(subscription); subscriptionHandlers.Add(subscriptionHandler); } catch (Exception e) { Trace.TraceError(e.Message); } } return(subscriptionHandlers); }
private IEnumerable <Subscription> GetSubscriptions(ModifiedFileModel modifiedFile) { return(Subscriptions.Where(s => s.TriggerPaths.Any(p => Matches(p, modifiedFile)))); }