func helpProvider()

in prow/plugins/bugzilla/bugzilla.go [64:317]


func helpProvider(config *plugins.Configuration, enabledRepos []config.OrgRepo) (*pluginhelp.PluginHelp, error) {
	configInfo := make(map[string]string)
	for _, repo := range enabledRepos {
		opts := config.Bugzilla.OptionsForRepo(repo.Org, repo.Repo)
		if len(opts) == 0 {
			continue
		}
		// we need to make sure the order of this help is consistent for page reloads and testing
		var branches []string
		for branch := range opts {
			branches = append(branches, branch)
		}
		sort.Strings(branches)
		var configInfoStrings []string
		configInfoStrings = append(configInfoStrings, "The plugin has the following configuration:<ul>")
		for _, branch := range branches {
			var message string
			if branch == plugins.BugzillaOptionsWildcard {
				message = "by default, "
			} else {
				message = fmt.Sprintf("on the %q branch, ", branch)
			}
			message += "valid bugs must "
			var conditions []string
			if opts[branch].IsOpen != nil {
				if *opts[branch].IsOpen {
					conditions = append(conditions, "be open")
				} else {
					conditions = append(conditions, "be closed")
				}
			}
			if opts[branch].TargetRelease != nil {
				conditions = append(conditions, fmt.Sprintf("target the %q release", *opts[branch].TargetRelease))
			}
			if opts[branch].ValidStates != nil && len(*opts[branch].ValidStates) > 0 {
				pretty := strings.Join(prettyStates(*opts[branch].ValidStates), ", ")
				conditions = append(conditions, fmt.Sprintf("be in one of the following states: %s", pretty))
			}
			if opts[branch].DependentBugStates != nil || opts[branch].DependentBugTargetReleases != nil {
				conditions = append(conditions, "depend on at least one other bug")
			}
			if opts[branch].DependentBugStates != nil {
				pretty := strings.Join(prettyStates(*opts[branch].DependentBugStates), ", ")
				conditions = append(conditions, fmt.Sprintf("have all dependent bugs in one of the following states: %s", pretty))
			}
			if opts[branch].DependentBugTargetReleases != nil {
				conditions = append(conditions, fmt.Sprintf("have all dependent bugs in one of the following target releases: %s", strings.Join(*opts[branch].DependentBugTargetReleases, ", ")))
			}
			switch len(conditions) {
			case 0:
				message += "exist"
			case 1:
				message += conditions[0]
			case 2:
				message += fmt.Sprintf("%s and %s", conditions[0], conditions[1])
			default:
				conditions[len(conditions)-1] = fmt.Sprintf("and %s", conditions[len(conditions)-1])
				message += strings.Join(conditions, ", ")
			}
			var updates []string
			if opts[branch].StateAfterValidation != nil {
				updates = append(updates, fmt.Sprintf("moved to the %s state", opts[branch].StateAfterValidation))
			}
			if opts[branch].AddExternalLink != nil && *opts[branch].AddExternalLink {
				updates = append(updates, "updated to refer to the pull request using the external bug tracker")
			}
			if opts[branch].StateAfterMerge != nil {
				updates = append(updates, fmt.Sprintf("moved to the %s state when all linked pull requests are merged", opts[branch].StateAfterMerge))
			}

			if len(updates) > 0 {
				message += ". After being linked to a pull request, bugs will be "
			}
			switch len(updates) {
			case 0:
			case 1:
				message += updates[0]
			case 2:
				message += fmt.Sprintf("%s and %s", updates[0], updates[1])
			default:
				updates[len(updates)-1] = fmt.Sprintf("and %s", updates[len(updates)-1])
				message += strings.Join(updates, ", ")
			}
			configInfoStrings = append(configInfoStrings, "<li>"+message+".</li>")
		}
		configInfoStrings = append(configInfoStrings, "</ul>")

		configInfo[repo.String()] = strings.Join(configInfoStrings, "\n")
	}
	str := func(s string) *string { return &s }
	yes := true
	no := false
	yamlSnippet, err := plugins.CommentMap.GenYaml(&plugins.Configuration{
		Bugzilla: plugins.Bugzilla{
			Default: map[string]plugins.BugzillaBranchOptions{
				"*": {
					ValidateByDefault: &yes,
					IsOpen:            &yes,
					TargetRelease:     str("release1"),
					Statuses:          &[]string{"NEW", "MODIFIED", "VERIFIED", "IN_PROGRESS", "CLOSED", "RELEASE_PENDING"},
					ValidStates: &[]plugins.BugzillaBugState{
						{
							Status: "MODIFIED",
						},
						{
							Status:     "CLOSED",
							Resolution: "ERRATA",
						},
					},
					DependentBugStatuses: &[]string{"NEW", "MODIFIED"},
					DependentBugStates: &[]plugins.BugzillaBugState{
						{
							Status: "MODIFIED",
						},
					},
					DependentBugTargetReleases: &[]string{"release1", "release2"},
					StatusAfterValidation:      str("VERIFIED"),
					StateAfterValidation: &plugins.BugzillaBugState{
						Status: "VERIFIED",
					},
					AddExternalLink:  &no,
					StatusAfterMerge: str("RELEASE_PENDING"),
					StateAfterMerge: &plugins.BugzillaBugState{
						Status:     "RELEASE_PENDING",
						Resolution: "RESOLVED",
					},
					StateAfterClose: &plugins.BugzillaBugState{
						Status:     "RESET",
						Resolution: "FIXED",
					},
					AllowedGroups: []string{"group1", "groups2"},
				},
			},
			Orgs: map[string]plugins.BugzillaOrgOptions{
				"org": {
					Default: map[string]plugins.BugzillaBranchOptions{
						"*": {
							ExcludeDefaults:   &yes,
							ValidateByDefault: &yes,
							IsOpen:            &yes,
							TargetRelease:     str("release1"),
							Statuses:          &[]string{"NEW", "MODIFIED", "VERIFIED", "IN_PROGRESS", "CLOSED", "RELEASE_PENDING"},
							ValidStates: &[]plugins.BugzillaBugState{
								{
									Status: "MODIFIED",
								},
								{
									Status:     "CLOSED",
									Resolution: "ERRATA",
								},
							},
							DependentBugStatuses: &[]string{"NEW", "MODIFIED"},
							DependentBugStates: &[]plugins.BugzillaBugState{
								{
									Status: "MODIFIED",
								},
							},
							DependentBugTargetReleases: &[]string{"release1", "release2"},
							StatusAfterValidation:      str("VERIFIED"),
							StateAfterValidation: &plugins.BugzillaBugState{
								Status: "VERIFIED",
							},
							AddExternalLink:  &no,
							StatusAfterMerge: str("RELEASE_PENDING"),
							StateAfterMerge: &plugins.BugzillaBugState{
								Status:     "RELEASE_PENDING",
								Resolution: "RESOLVED",
							},
							StateAfterClose: &plugins.BugzillaBugState{
								Status:     "RESET",
								Resolution: "FIXED",
							},
							AllowedGroups: []string{"group1", "groups2"},
						},
					},
					Repos: map[string]plugins.BugzillaRepoOptions{
						"repo": {
							Branches: map[string]plugins.BugzillaBranchOptions{
								"branch": {
									ExcludeDefaults:   &no,
									ValidateByDefault: &yes,
									IsOpen:            &yes,
									TargetRelease:     str("release1"),
									Statuses:          &[]string{"NEW", "MODIFIED", "VERIFIED", "IN_PROGRESS", "CLOSED", "RELEASE_PENDING"},
									ValidStates: &[]plugins.BugzillaBugState{
										{
											Status: "MODIFIED",
										},
										{
											Status:     "CLOSED",
											Resolution: "ERRATA",
										},
									},
									DependentBugStatuses: &[]string{"NEW", "MODIFIED"},
									DependentBugStates: &[]plugins.BugzillaBugState{
										{
											Status: "MODIFIED",
										},
									},
									DependentBugTargetReleases: &[]string{"release1", "release2"},
									StatusAfterValidation:      str("VERIFIED"),
									StateAfterValidation: &plugins.BugzillaBugState{
										Status: "VERIFIED",
									},
									AddExternalLink:  &no,
									StatusAfterMerge: str("RELEASE_PENDING"),
									StateAfterMerge: &plugins.BugzillaBugState{
										Status:     "RELEASE_PENDING",
										Resolution: "RESOLVED",
									},
									StateAfterClose: &plugins.BugzillaBugState{
										Status:     "RESET",
										Resolution: "FIXED",
									},
									AllowedGroups: []string{"group1", "groups2"},
								},
							},
						},
					},
				},
			},
		},
	})
	if err != nil {
		logrus.WithError(err).Warnf("cannot generate comments for %s plugin", PluginName)
	}
	pluginHelp := &pluginhelp.PluginHelp{
		Description: "The bugzilla plugin ensures that pull requests reference a valid Bugzilla bug in their title.",
		Config:      configInfo,
		Snippet:     yamlSnippet,
	}
	pluginHelp.AddCommand(pluginhelp.Command{
		Usage:       "/bugzilla refresh",
		Description: "Check Bugzilla for a valid bug referenced in the PR title",
		Featured:    false,
		WhoCanUse:   "Anyone",
		Examples:    []string{"/bugzilla refresh"},
	})
	pluginHelp.AddCommand(pluginhelp.Command{
		Usage:       "/bugzilla assign-qa",
		Description: "(DEPRECATED) Assign PR to QA contact specified in Bugzilla",
		Featured:    false,
		WhoCanUse:   "Anyone",
		Examples:    []string{"/bugzilla assign-qa"},
	})
	pluginHelp.AddCommand(pluginhelp.Command{
		Usage:       "/bugzilla cc-qa",
		Description: "Request PR review from QA contact specified in Bugzilla",
		Featured:    false,
		WhoCanUse:   "Anyone",
		Examples:    []string{"/bugzilla cc-qa"},
	})
	return pluginHelp, nil
}