func()

in tools/commentMonitor/client.go [90:117]


func (c *commentMonitorClient) extractArgs(command string) error {
	var err error
	if c.regex != nil {
		// Add command arguments.
		commandArgs := c.regex.FindStringSubmatch(command)[1:]
		commandArgsNames := c.regex.SubexpNames()[1:]
		for i, argName := range commandArgsNames {
			if argName == "" {
				return fmt.Errorf("using named groups is mandatory")
			}
			c.allArgs[argName] = commandArgs[i]
		}

		// Add non-comment arguments if any.
		c.allArgs["PR_NUMBER"] = strconv.Itoa(c.ghClient.pr)
		c.allArgs["LAST_COMMIT_SHA"], err = c.ghClient.getLastCommitSHA()
		if err != nil {
			return fmt.Errorf("%v: could not fetch SHA", err)
		}

		// TODO (geekodour) : We could run this in a seperate method.
		err = c.ghClient.createRepositoryDispatch(c.eventType, c.allArgs)
		if err != nil {
			return fmt.Errorf("%v: could not create repository_dispatch event", err)
		}
	}
	return nil
}